public ActionResult DemandCreate(DemandModel model) { //Проверяем модель на валидность if (!ModelState.IsValid) { return(View(model)); } int id; using (ApplicationDbContext db = new ApplicationDbContext()) { var newDemand = new Demand { Date = DateTime.Now, DescriptionIssue = model.DescriptionIssue, Status = db.DemandStatuses.SingleOrDefault(x => x.Id == model.Status), Priority = db.Priorities.SingleOrDefault(x => x.Id == model.Priority), User = db.Users.SingleOrDefault(x => x.Id == model.User), Phone = model.Phone, Master = model.Master != null?db.Users.SingleOrDefault(x => x.Id == model.Master) : null, Manager = model.Manager != null?db.Users.SingleOrDefault(x => x.Id == model.Manager) : null, DecisionDescription = model.DecisionDescription, Equipment = model.Equipment, DecisionHours = model.DecisionHours }; db.Demands.Add(newDemand); db.SaveChanges(); id = newDemand.Id; } TempData["success"] = "Новая завка создана под номером " + id; return(RedirectToAction("Demands", "Chief")); }
public ActionResult DemandEdit(int id) { Demand demand; using (ApplicationDbContext db = new ApplicationDbContext()) { demand = db.Demands.Include(x => x.Master).Include(x => x.Priority).Include(x => x.Status).Include(x => x.User).Include(x => x.Manager).SingleOrDefault(x => x.Id == id); } var model = new DemandModel(); if (demand != null) { model.Id = demand.Id; model.Priority = demand.Priority.Id; model.User = demand.User.Id; model.Manager = demand.Manager?.Id; model.Master = demand.Master?.Id; model.DescriptionIssue = demand.DescriptionIssue; model.Status = demand.Status.Id; model.Phone = demand.Phone; model.DecisionDescription = demand.DecisionDescription; model.DecisionHours = demand.DecisionHours; model.Equipment = demand.Equipment; model.Date = demand.Date; } return(View(model)); }
//[ValidateAntiForgeryToken] public ActionResult Edit(DemandModel demand) { if (ModelState.IsValid) { var dbDemand = db.Demands.Include(d => d.DemandLogs).First(d => d.Id == demand.Id); dbDemand.Priority = demand.Priority; dbDemand.RAG = demand.RAG; dbDemand.DemandStatus = demand.DemandStatus; dbDemand.ServiceLine = demand.ServiceLine; dbDemand.Phase = demand.Phase; var newDemandLog = new DemandLog() { Priority = demand.Priority, RAG = demand.RAG, DemandStatus = demand.DemandStatus, ServiceLine = demand.ServiceLine, Phase = demand.Phase, AssignedTeam = demand.AssignedTeam, TeamStatus = demand.TeamStatus, Comments = demand.Comments, UpdatedDate = DateTime.Now, DemandId = demand.Id }; dbDemand.DemandLogs.Add(newDemandLog); db.SaveChanges(); //TODO:create DemandDTO newDemandLog.Demand = null; return(Json(JsonConvert.SerializeObject(newDemandLog))); } return(Json(JsonConvert.SerializeObject(new { errorMsg = "invalid Object" }))); }
public ActionResult DemandEdit(DemandModel model) { //Проверяем модель на валидность if (!ModelState.IsValid) { return(View(model)); } using (ApplicationDbContext db = new ApplicationDbContext()) { var demand = db.Demands.SingleOrDefault(x => x.Id == model.Id); if (demand == null) { ModelState.AddModelError("", "Заявка не найдена"); return(View(model)); } var oldStatus = demand.Status; var newStatus = db.DemandStatuses.SingleOrDefault(x => x.Id == model.Status); demand.DecisionDescription = model.DecisionDescription; demand.DecisionHours = model.DecisionHours; demand.Equipment = model.Equipment; demand.Status = db.DemandStatuses.SingleOrDefault(x => x.Id == model.Status); db.SaveChanges(); //Если статус заявки изменился отправляем пользователю письмо if (oldStatus.Id != newStatus.Id) { UserManager.SendEmail(demand.User.Id, "Изменение статуса заявки", "Статус Вашей заявки №" + demand.Id + " изменился с \"" + oldStatus.Caption + "\" на \"" + newStatus.Caption + "\""); } TempData["success"] = "Завка №" + demand.Id + " успешно изменена"; return(RedirectToAction("Demands", "Master")); } }
public ActionResult DemandCreate() { var model = new DemandModel { User = User.Identity.GetUserId() }; return(View(model)); }
/// <summary> /// Clone /// </summary> /// <param name="model"></param> /// <returns></returns> public static DemandModel Clone(this DemandModel model) { if (model == null) { return(null); } return(new DemandModel { Key = model.Key, Value = model.Value, Operator = model.Operator }); }
/// <summary> /// Create model /// </summary> /// <param name="model"></param> /// <returns></returns> public static DemandApiModel ToApiModel( this DemandModel model) { if (model == null) { return(null); } return(new DemandApiModel { Key = model.Key, Operator = (Api.Jobs.Models.DemandOperators?)model.Operator, Value = model.Value }); }
public DemandModel GetDemand(string id) { var collection = GetDemandsCollection(); DemandModel demand = null; if (collection != null) { demand = (from e in collection.AsQueryable() where e.bookid.ToString().ToLower().Contains(id.ToLower()) select e) as DemandModel; } return(demand); }
public ActionResult DemandDelete(int id) { using (ApplicationDbContext db = new ApplicationDbContext()) { var demand = db.Demands.SingleOrDefault(x => x.Id == id); var model = new DemandModel(); if (demand != null) { model.Id = demand.Id; model.Date = demand.Date; } return(View(model)); } }
/// <summary> /// Convert to storage /// </summary> /// <param name="model"></param> /// <param name="jobId"></param> /// <returns></returns> public static DemandDocument ToDocumentModel(this DemandModel model, string jobId) { if (model == null) { return(null); } return(new DemandDocument { Key = model.Key, Value = model.Value, Operator = model.Operator, JobId = jobId }); }
private List <SolutionModel> PrepareOneDemandPathCombinations(DemandModel demand) { var oneDemandPathCombinations = new List <SolutionModel>(); var combinationsNumber = AdditionalFunctions.GetBinaryCoefficient(demand.NumberOfPaths + demand.DemandVolume - 1, demand.DemandVolume); List <List <int> > combinations = PrepareCombinations(demand.DemandVolume, demand.NumberOfPaths); for (int i = 0; i < combinationsNumber; i++) { var xes = new Dictionary <PModel, int>(); foreach (var path in demand.Paths) { xes.Add(new PModel(demand.DemandId, path.PathId), combinations.ElementAt(i).ElementAt(path.PathId - 1)); } oneDemandPathCombinations.Add(new SolutionModel(xes)); } return(oneDemandPathCombinations); }
public ActionResult DemandEdit(int id) { Demand demand; using (ApplicationDbContext db = new ApplicationDbContext()) { demand = db.Demands.Include(x => x.Master).Include(x => x.Priority).Include(x => x.Status).Include(x => x.User).Include(x => x.Manager).SingleOrDefault(x => x.Id == id); } var model = new DemandModel(); if (demand != null) { model.Id = demand.Id; model.Priority = demand.Priority.Id; model.User = demand.User.Id; model.Manager = demand.Manager?.Id; model.Master = demand.Master?.Id; model.DescriptionIssue = demand.DescriptionIssue; model.Status = demand.Status.Id; model.Phone = demand.Phone; model.DecisionDescription = demand.DecisionDescription; model.DecisionHours = demand.DecisionHours; model.Equipment = demand.Equipment; model.Date = demand.Date; model.DescriptionIssue = demand.DescriptionIssue; model.User = demand.User.Id; model.Phone = demand.Phone; //Если исполнитель по заявке не текущий пользователь редиректим назад if (demand.User?.Id != User.Identity.GetUserId()) { TempData["errors"] = "У Вас нет доступа к завке №" + demand.Id + ", т.к. она Вам не принадлежит"; return(RedirectToAction("Demands", "User")); } } return(View(model)); }
public ActionResult DemandDelete(DemandModel model) { //Проверяем модель на валидность if (model == null) { ModelState.AddModelError("", "Идентификатор заявки не определен."); return(View(model)); } using (ApplicationDbContext db = new ApplicationDbContext()) { var demand = db.Demands.SingleOrDefault(x => x.Id == model.Id); //Если заявка не найдена то возвращаем ошибку if (demand == null) { ModelState.AddModelError("", "Заявка не найдена."); return(View(model)); } var id = demand.Id; db.Demands.Remove(demand); db.SaveChanges(); TempData["success"] = "Завка №" + id + " успешно удалена"; return(RedirectToAction("Demands", "Chief")); } }