Task.assignee is always null [asana] - asana

I'm using AsanaNet - which works great, but task assignee is always null, even though the Asana console shows these tasks as having an assignee.
var asana = new Asana("zzzzzzzzzzzzzzzzzzzzzzzzzzzz", AuthenticationType.Basic, errorCallback);
asana.GetWorkspaces(o =>
{
foreach (AsanaWorkspace sp in o)
{
asana.GetUsersInWorkspace(sp, u =>
{
foreach (AsanaUser user in u)
{
//Get a List of WORKSPACES
asana.GetTasksInWorkspace(sp, user, t =>
{
foreach (AsanaTask task in t)
{
asana.GetProjectsOnATask(task, p =>
{
foreach (AsanaProject project in p)
{
bool bSuccess = ProcessTask(task, project);
}
}).Wait();
}
}).Wait();
}
}).Wait();
}
}).Wait();

Related

How to edit/update records using "TryUpdateModel" with "User.Identity.GetUserId()" in mvc.net?

This following code works fine
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit(int? id, string[] selectedCourses)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
var instructorToUpdate = db.Instructors
.Include(i => i.OfficeAssignment)
.Include(i => i.Courses)
.Where(i => i.ID == id)
.Single();
if (TryUpdateModel(instructorToUpdate, "",
new string[] { "LastName", "FirstMidName", "HireDate", "OfficeAssignment" }))
{
try
{
if (String.IsNullOrWhiteSpace(instructorToUpdate.OfficeAssignment.Location))
{
instructorToUpdate.OfficeAssignment = null;
}
UpdateInstructorCourses(selectedCourses, instructorToUpdate);
db.SaveChanges();
return RedirectToAction("Index");
}
catch (RetryLimitExceededException /* dex */)
{
//Log the error (uncomment dex variable name and add a line here to write a log.
ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator.");
}
}
PopulateAssignedCourseData(instructorToUpdate);
return View(instructorToUpdate);
}
private void UpdateInstructorCourses(string[] selectedCourses, Instructor instructorToUpdate)
{
if (selectedCourses == null)
{
instructorToUpdate.Courses = new List<Course>();
return;
}
var selectedCoursesHS = new HashSet<string>(selectedCourses);
var instructorCourses = new HashSet<int>
(instructorToUpdate.Courses.Select(c => c.CourseID));
foreach (var course in db.Courses)
{
if (selectedCoursesHS.Contains(course.CourseID.ToString()))
{
if (!instructorCourses.Contains(course.CourseID))
{
instructorToUpdate.Courses.Add(course);
}
}
else
{
if (instructorCourses.Contains(course.CourseID))
{
instructorToUpdate.Courses.Remove(course);
}
}
}
}
But I don't want to get id from view and I am using string id = User.Identity.GetUserId(); but only my checkboxes are getting updated and not the other database.
I tried db.Entry(abc).State = EntityState.Modified; but it gives an error. It says, context is already in use. How to update both tables?

run EF6 async request in mvc controller

I have mvc 5 and EF6 and never really use async in mvc before so want ask best way for run sql requests.
public ActionResult SearchTest(string id)
{
string searchtxt = UsefulClass.ConvertObjectToString(id).Replace(",", " ").Trim();
var model = new SearchResult();
if (!String.IsNullOrEmpty(searchtxt))
{
//get the data from 3 requests
var ArtistList = _db.Artists.SqlQuery("SELECT top 6 * FROM Artists WHERE CONTAINS(Name, N'Queen') and TopTracksStatus = 1 and GrabStatus > 1 order by playcount desc").ToList();
var tracks = _db.Database.SqlQuery<TrackInfo>("exec SearchTracks #SearchText=N'Queen', #TopCount=10,#LengthCount=100").ToList();
var TagsList = _db.Tags.Where(x => x.TagName.Contains(searchtxt)).Take(5).ToList();
//work with ArtistList and add to model
if (ArtistList.Any())
{
int i = 0;
foreach (var artist in ArtistList)
{
i++;
if (i == 1) //top artist
{
model.BestArtist = artist;
model.BestArtistTrackCount = _db.TopTracks.Count(x => x.Artist_Id == artist.Id);
}
else
{
model.ArtistList = ArtistList.Where(x => x.Id != model.BestArtist.Id);
break;
}
}
}
//work with tracks and add to model
if (tracks.Any())
{
model.TopTrackList = tracks;
}
//work with tags and add to model
if (TagsList.Any())
{
model.TagList = TagsList;
}
}
return View(model);
}
Here I have 3 requests which return ArtistList, tracks, TagsList and I need add them to model and then pass to view. How to do it in async way?
Try below example, hope it gives you a good idea.
public async Task<ActionResult> SearchTestAsync(string id)
{
string searchtxt = UsefulClass.ConvertObjectToString(id).Replace(",", " ").Trim();
var model = new SearchResult();
if (!String.IsNullOrEmpty(searchtxt))
{
var art = GetArtistListResulst(model);
var track = GetTracksResults(model);
var tag = GetTagsListResults(model,searchtxt);
await Task.WhenAll(art, track, tag);
}
return View(model);
}
private Task GetArtistListResulst(SearchResult model)
{
return Task.Run(() =>
{
var artistList = _db.Artists.SqlQuery("SELECT top 6 * FROM Artists WHERE CONTAINS(Name, N'Queen') and TopTracksStatus = 1 and GrabStatus > 1 order by playcount desc").ToList();
// You don't need to use foreach because the artistList is ordered by playcount already.
model.BestArtist = artistList.Take(1);
model.BestArtistTrackCount = _db.TopTracks.Count(x => x.Artist_Id == model.BestArtist.Id);
model.ArtistList = artistList.Where(x => x.Id != model.BestArtist.Id);
});
}
private Task GetTracksResults(SearchResult model)
{
return Task.Run(() =>
{
model.TopTrackList = _db.Database.SqlQuery<TrackInfo>("exec SearchTracks #SearchText=N'Queen', #TopCount=10,#LengthCount=100").ToList();
});
}
private Task GetTagsListResults(SearchResult model, string searchtxt)
{
return Task.Run(() =>
{
model.TagsList = _db.Tags.Where(x => x.TagName.Contains(searchtxt)).Take(5).ToList();
});
}

Delete a context record from grid in kendo UI using LINQ

Hi Im using kendo ui grid in my project.
This is my code to insert records in database.
public static void Insert(StudentViewModel student)
{
student.StudentId = All().OrderByDescending(p => p.StudentId).First().StudentId + 1;
//All().Insert(0, student);
UniRegEntities uniRegEntities = new UniRegEntities();
Student stu =new Student();
stu.FName = student.FirstName;
stu.LName = student.LastName;
stu.Gender = uniRegEntities.Genders.Where(x => x.Title == student.Gender).FirstOrDefault();
stu.Id = student.StudentId;
uniRegEntities.Students.Add(stu);
uniRegEntities.SaveChanges();
}
And this is my update statement.
public static void Update(StudentViewModel student)
{
UniRegEntities context = new UniRegEntities();
var studentToUpdate = context.Students.Where(x => x.Id == student.StudentId).FirstOrDefault();
studentToUpdate.FName = student.FirstName;
studentToUpdate.LName = student.LastName;
studentToUpdate.Gender = context.Genders.Where(x => x.Title == student.Gender).FirstOrDefault();
context.SaveChanges();
}
Anyone can suggest me the delete method?
You can either get an entity from the DB and then delete it or create one and then delete it.
So:
var e = // Get
ctx.DeleteObject(e);
ctx.SaveChanges();
or
var e = new Foo() { FooId = id };
ctx.Entity.Attach(e);
ctx.DeleteObject(e);
ctx.SaveChanges();
Applied to your situation:
You are getting a record so you want to use DeleteObject()
public static void Update(StudentViewModel student)
{
UniRegEntities context = new UniRegEntities();
var studentToDelete = context.Students.Where(x => x.Id == student.StudentId).FirstOrDefault();
context.Students.DeleteObject(studentToUpdate);
context.SaveChanges();
}
context.Students.Remove(context.students.Single(x=>x.Id==student.Id));
Can you please try with below code snippet?
using (var db= new AppContext(ConnectionStr))
{
try
{
con.Configuration.AutoDetectChangesEnabled = false;
var o = new Student { StudentId = student.StudentId };
db.Students.Attach(o);
db.Students.Remove(o);
db.SaveChanges();
}
catch (Exception ex)
{
throw new Exception(ex.InnerException.Message);
}
finally
{
con.Configuration.AutoDetectChangesEnabled = true;
}
}

Cypher Query Issues Neo4j C# Client

I am getting an error on the following code that says:
Here is the code, I need this method to return the Max Value? is it an IEnumerable or an int?
public IEnumerable<int> GraphGetMaxVersion(IEnumerable<Node<VersionNode>> nodeId)
{
IEnumerable<int> nodes = null;
clientConnection = graphOperations.GraphGetConnection();
var query = clientConnection
.Cypher
.Start(new
{
n = nodeId
})
.Return((maxVersion) => new
{
MaxVersion = Return.As<int>("max.Version")
});
nodes = query.Results;
return nodes;
}
Here is the query I would like to perform:
START n=node(2,3,4)
RETURN max(n.property)
You want this:
public int GraphGetMaxVersion(IEnumerable<NodeReference<VersionNode>> nodes)
{
return graphClient.Cypher
.Start(new { n = nodes })
.Return(() => Return.As<int>("max(n.Version)"))
.Results
.Single();
}
I haven't tested that. I just bashed it out here in the textbox, but it should work.
If you don't need to return a complex type, don't. That is, turn Return(() => new { Foo = All.Count() }) into Return(() => All.Count()).
If you don't need to use an identity in your return lambda, don't pass it in. That is, this argument is pointless: Return((somePointlessIdentityHere) => All.Count())
Use either Neo4jClient 1.0.0.570 or above, or change .Start(new { n = nodes }) to .Start(new { n = nodes.ToArray() }).
You should so the following:
// Return Max follwoer node ID:
public float ReturnMaxFollowerID(IGraphClient Client)
{
return Client.Cypher
.Match("(n:User)")
.Return(() => Return.As<float>("max(n.userID)"))
.Results
.Single();
}
No errors are thrown when I made these changes to the method after reading this post.
public int GraphGetMaxVersion(int nodeId)
{
int nodes = 0;
clientConnection = graphOperations.GraphGetConnection();
var query = clientConnection
.Cypher
.Start(new
{
n = nodeId
})
.Return((maxVersion) => new
{
MaxVersion = Return.As<int>("max(n.Version)")
})
.Results
.Single();
nodes = query.MaxVersion;
return nodes;
}

Kendo UI Grid - Inline Edit not change to database

I'm following the demo grid-edit inline
It works but not change to database, it only change the list that popolated
what i have to do next
here the code
public static IList<Book> All()
{
IList<Book> result = (IList<Book>)HttpContext.Current.Session["Books"];
if (result == null)
{
HttpContext.Current.Session["Books"] = result =
(from book in new LibraryModel().Books
select new Book
{
PKiBookID=book.PKiBookID,
SBookName = book.SBookName,
SBookWriter= book.SBookWriter,
SDescription=book.SDescription,
BStatus=book.BStatus,
FKiBookType=book.FKiBookType
}).ToList();
}
return result;
}
public static Book One(Func<Book, bool> predicate)
{
return All().Where(predicate).FirstOrDefault();
}
public static void Insert(Book book)
{
//book.PKiBookID = All().OrderByDescending(p => p.PKiBookID).First().PKiBookID + 1;
All().Insert(0,book);
}
public static void Update(Book book)
{
Book target = One(p => p.PKiBookID == book.PKiBookID);
if (target != null)
{
target.SBookName = book.SBookName;
target.SBookWriter = book.SBookWriter;
target.SDescription = book.SDescription;
target.BStatus = book.BStatus;
target.BookType = new LibraryModel().BookTypes.Single(s => s.PKiBookTypeID == book.FKiBookType);
}
}
This exception is quite well known and there are many posts how to avoid it. It is also covered in the Documentation.

Resources