public ActionResult _DoAddTaskJson(Tasks DatiTask, int TaskID, int UserID) { TaskUserView tasksUsers = new TaskUserView(); Tasks task = null; Users user = null; using (RewardsForYouEntities db = new RewardsForYouEntities()) { task = db.Tasks.Where(l => l.TaskID == TaskID).FirstOrDefault(); user = db.Users.Where(l => l.UserID == UserID).FirstOrDefault(); Missions mission = new Missions { Tasks = task, Users = user, UserID = user.UserID, TaskID = task.TaskID, StartDate = DateTime.Now, EndDate = task.ExpiryDate, Note = "", Status = 0 }; db.Missions.Add(mission); db.SaveChanges(); } return(Json(new { messaggio = $"Task : {DatiTask.TaskID} assegnato con successo" })); }
//View The Task public ActionResult AssegnaTask(int UserID) { TaskUserView tasksUsers = new TaskUserView(); using (RewardsForYouEntities db = new RewardsForYouEntities()) { tasksUsers.task = db.Tasks.ToList(); } tasksUsers.UsersID = UserID; return(PartialView(tasksUsers)); }
//Add the Task at Employee public ActionResult _DoAddTaskJson(Tasks DatiTask, int TaskID, int UserID) { TaskUserView tasksUsers = new TaskUserView(); Tasks task = null; Users user = null; List <Missions> missions = null; Missions m = null; using (RewardsForYouEntities db = new RewardsForYouEntities()) { task = db.Tasks.Where(l => l.TaskID == TaskID).FirstOrDefault(); user = db.Users.Where(l => l.UserID == UserID).FirstOrDefault(); missions = db.Missions.ToList(); //controllo se il task è stato gia assegnato m = db.Missions.Where(l => l.TaskID == task.TaskID && l.UserID == user.UserID && l.Status == 0).FirstOrDefault(); if (m != null) { return(Json(new { messaggio = $"Il task è stato già assegnato" })); } else { DateTime start = DateTime.Now.Date; Missions mission = new Missions { Tasks = task, Users = user, UserID = user.UserID, TaskID = task.TaskID, StartDate = DateTime.Now, EndDate = task.ExpiryDate, Note = "", Status = 0, DesiredEndDate = start.AddMonths(task.TimeSpan) }; db.Missions.Add(mission); db.SaveChanges(); } } return(Json(new { messaggio = $"Task : {DatiTask.TaskID} assegnato con successo" })); }
// list of subscribers to work public ActionResult Work() { List <Task> tasks = logic.GetWorks(); List <TaskUserView> works = new List <TaskUserView>(); foreach (Task task in tasks) { TaskUserView work = new TaskUserView(); work.TaskId = task.TaskId; work.AddDate = task.AddDate; work.Customer = task.Customer; work.Description = task.Description; work.Name = task.Name; User user = userLogic.GetUserById(task.PerfomerId); work.PerfomerName = user.UserName; works.Add(work); } ViewBag.NumberOfDone = works.Count; return(View(works)); }