public async Task <IActionResult> EditFunction(string id) { ViewBag.userMenu = GetMenu(); if (id == null) { return(NotFound()); } if (!checkuser()) { return(RedirectToAction("Index", "Home")); } var Function = await context.Function.SingleOrDefaultAsync(m => m.FunctionId == id); var Teamtask = await context.TeamTask.SingleOrDefaultAsync(m => m.FunctionId == id); var e = new CreateFunctionInputModel { ProjectNumber = Function.ProjectNumber, TaskId = Function.TaskId, FunctionName = Function.FunctionName, FunctionStart = Function.FunctionStart, FunctionEnd = Function.FunctionEnd, FunctionId = Function.FunctionId, UserId = Teamtask.UserId, ProjectResponsible = Teamtask.ProjectResponsible }; if (Function == null) { return(NotFound()); } ViewData["UserSSPM"] = new SelectList(context.UserSspm.Join(context.UserAssignGroup, u => u.UserId, ua => ua.UserId, (u, ua) => new { UserId = u.UserId, Firstname = u.Firstname, GroupId = ua.GroupId, Status = u.Status }).Where(ua => ua.GroupId.Equals("10") || ua.GroupId.Equals("50") && ua.Status.Equals("A") ) , "UserId", "Firstname"); ViewData["naemFunction"] = Function.FunctionName; return(PartialView("EditFunction", e)); }
public async Task <IActionResult> CreateFunction(string pnum, CreateFunctionInputModel inputModel) { ViewBag.userMenu = GetMenu(); try { var id = (from u in context.RunningNumber where u.Type.Equals("FunctionID") select u).FirstOrDefault(); int num; if (id.Number == null) { num = 100001; } else { num = Convert.ToInt32(id.Number); num = num + 1; } var nameRFC = ""; if (inputModel.RSC.Equals("T")) { nameRFC = "[RFC]_" + inputModel.FunctionName; } else { nameRFC = inputModel.FunctionName; } Models.Function ord = new Models.Function { ProjectNumber = inputModel.ProjectNumber, TaskId = inputModel.TaskId, FunctionName = nameRFC, FunctionStart = inputModel.FunctionStart, FunctionEnd = inputModel.FunctionEnd, FunctionId = num.ToString() }; // Add the new object to the Orders collection. context.Function.Add(ord); await context.SaveChangesAsync(); var query = from xx in context.RunningNumber where xx.Type.Equals("FunctionID") select xx; foreach (RunningNumber RunFunctionID in query) { RunFunctionID.Number = num.ToString(); } // Submit the changes to the database. try { await context.SaveChangesAsync(); try { Models.TeamTask ord2 = new Models.TeamTask { FunctionId = num.ToString(), UserId = inputModel.UserId, ProjectResponsible = inputModel.ProjectResponsible, TaskId = inputModel.TaskId, ProjectNumber = inputModel.ProjectNumber }; context.TeamTask.Add(ord2); await context.SaveChangesAsync(); } catch (Exception x) { Console.WriteLine(x); } } catch (Exception e) { Console.WriteLine(e); // Provide for exceptions. } var SendBack = "false"; if (inputModel.RSC.Equals("T")) { SendBack = "true"; } return(RedirectToAction("CreateFunction", "ProjectManagement", new RouteValueDictionary( new { Controller = "ProjectManagement", Action = "CreateFunction", id = inputModel.TaskId, rsc = SendBack }))); } catch (Exception ex) { var message = ex.Message; return(View()); } }
public async Task <IActionResult> EditFunction(string id, CreateFunctionInputModel editModel) { var loggedInUser = HttpContext.User; var loggedInUserName = loggedInUser.Identity.Name; ViewBag.userMenu = GetMenu(); var query = (from x in context.Function where x.FunctionId.Equals(editModel.FunctionId) select x).FirstOrDefault(); if (editModel.FunctionId != query.FunctionId) { return(NotFound()); } if (ModelState.IsValid) { try { //context.Update(ord); var addquery = from test in context.Function where test.FunctionId.Equals(editModel.FunctionId) select test; foreach (Models.Function UserUpdate in addquery) { UserUpdate.FunctionName = editModel.FunctionName; UserUpdate.FunctionEnd = editModel.FunctionEnd; UserUpdate.FunctionStart = editModel.FunctionStart; } await context.SaveChangesAsync(); try { var addquery2 = from test2 in context.TeamTask where test2.FunctionId.Equals(editModel.FunctionId) select test2; foreach (TeamTask UserUpdate2 in addquery2) { UserUpdate2.UserId = editModel.UserId; UserUpdate2.ProjectResponsible = editModel.ProjectResponsible; } await context.SaveChangesAsync(); } catch (Exception e) { Console.WriteLine(e); } } catch (DbUpdateConcurrencyException) { throw; } var segment = query.TaskId.ToString(); return(RedirectToAction("CreateFunction", "ProjectManagement", new RouteValueDictionary( new { Controller = "ProjectManagement", Action = "CreateFunction", id = segment }))); } return(View(query.FunctionId)); }