// public void addPastRole(int wrId, string dateStart, string dateEnd) { DateTime dtStart = DateTime.ParseExact(dateStart, "dd/MM/yyyy", CultureInfo.InvariantCulture); DateTime dtEnd = DateTime.ParseExact(dateEnd, "dd/MM/yyyy", CultureInfo.InvariantCulture); var WorkRoleUser = new WorkRolesUsersDetails { WorkRoleId = wrId, UserDetailsId = User.Identity.GetUserId(), FocusStart = dtStart, FocusEnd = dtEnd.AddYears(1), isActive = false }; db.WorkRolesUsersDetails.Add(WorkRoleUser); db.SaveChanges(); //return Json(str); }
// public ActionResult unfocusFromRole(int?id) { //where role id and user id are equal to the ones passed as parameters //update isActive to false, update end date with the current date //int? roleid = id; string currentUserId = User.Identity.GetUserId(); UserDetails userDetails = db.UsersDetails.Where(c => c.identtyUserId == currentUserId) .FirstOrDefault(); int UsrCompanyId = userDetails.CompanyId; var WorkRolesQuery = db.WorkRoles.Where(c => c.CompanyId == UsrCompanyId).ToList(); //check if some of the roles match with those the user already is 'focused' on //if there are such remove them from the list and then pass it to the view WorkRolesUsersDetails workrolesusersdetailsQuery = db.WorkRolesUsersDetails .Where(m => m.UserDetailsId == currentUserId && m.isActive == true && m.WorkRoleId == id).FirstOrDefault(); //var rolesCount = workrolesusersdetailsQuery.Count; workrolesusersdetailsQuery.isActive = false; workrolesusersdetailsQuery.FocusEnd = DateTime.Now; db.Entry(workrolesusersdetailsQuery).State = EntityState.Modified; db.SaveChanges(); //foreach (var wu in workrolesusersdetailsQuery) //{ // if (wu.FocusEnd > DateTime.Now) // { // WorkRolesQuery.RemoveAll((x) => x.WorkRoleId == wu.WorkRoleId); // } return(RedirectToAction("Index")); }
public ActionResult addWorkRoleUser(int?id) //change to normal method { int?roleid = id; //on button click check in the db if a user doesn't already have three assigned roles for one year back. //if the user doesn't then insert the choosen role id and the user id into the database //with the dates as well current date + one year ahead as an end date //дд DateTime date = DateTime.Now; var WorkRoleUser = new WorkRolesUsersDetails { WorkRoleId = id, UserDetailsId = User.Identity.GetUserId(), FocusStart = date, FocusEnd = date.AddYears(1), isActive = true }; db.WorkRolesUsersDetails.Add(WorkRoleUser); db.SaveChanges(); return(RedirectToAction("DisplayListOfRolesUser")); //return View(); }