Example #1
0
        public IActionResult EditNeeds([FromServices] DataContext dataContext, long id)
        {
            Need need = dataContext.Needs
                        .Include(n => n.NeedPpeTypes)
                        .Include(n => n.NeedNotes)
                        .ThenInclude(n => n.Note)
                        .ThenInclude(n => n.User)
                        .Single(n => n.Id == id);
            List <Supplier> suppliers = dataContext.Suppliers.ToList();

            return(View(EditNeedsViewModel.FromEntities(need, suppliers)));
        }
Example #2
0
        public IActionResult EditNeeds([FromServices] DataContext dataContext, EditNeedsPost data)
        {
            SimpleNotifier noty = notifier();

            if (!ModelState.IsValid)
            {
                List <Supplier> suppliers = dataContext.Suppliers.ToList();
                noty.AddMessage(MsgTypes.Warning, "Problems saving, please try again");
                return(View("EditNeeds", EditNeedsViewModel.FromPostData(data, suppliers)));
            }
            else
            {
                Need existingNeed = dataContext.Needs.Include(p => p.NeedPpeTypes).Single(n => n.Id == data.Request.Id);
                existingNeed.Modify(data, currentUserId);
                dataContext.SaveChanges(currentUserName);
                noty.AddMessage(MsgTypes.Success, "Successfully updated the Request");
                return(Redirect("/requests"));
            }
        }