Esempio n. 1
0
        public async Task <ActionResult> CreateNewFact(CreateNewFactRecordViewModel model)
        {
            var user = await UserManager.FindByIdAsync(User.Identity.GetUserId());

            var context = HttpContext.GetOwinContext().Get <ApplicationDbContext>();

            if (ModelState.IsValid)
            {
                if (model.Id == 0)
                {
                    FactRecord factRecord = new FactRecord()
                    {
                        Date       = model.Date,
                        Number     = model.Number,
                        PlanRecord = GetPlanRecord(model.IdPlanRecord)
                    };
                    context.FactRecords.Add(factRecord);
                    context.SaveChanges();
                    return(RedirectToAction("Index", new { Message = ManageMessageId.AddNewFactRecord }));
                }
                var factRecordForUpdate = (from c in context.FactRecords
                                           where c.Id == model.Id
                                           select c).FirstOrDefault();
                factRecordForUpdate.Date   = model.Date;
                factRecordForUpdate.Number = model.Number;
                context.SaveChanges();
                return(RedirectToAction("Index", new { Message = ManageMessageId.UpdateFactRecord }));
            }

            // Это сообщение означает наличие ошибки; повторное отображение формы
            return(View(model));
        }
Esempio n. 2
0
        //
        //  GET: /Manage/Create new fact or edit fact
        public ActionResult CreateNewFact(int?idPlan, int id = 0)
        {
            if (id != 0)
            {
                var context = HttpContext.GetOwinContext().Get <ApplicationDbContext>();

                var factRecord = (from c in context.FactRecords.Include("PlanRecord")
                                  where c.Id == id
                                  select c).FirstOrDefault();
                CreateNewFactRecordViewModel model = new CreateNewFactRecordViewModel()
                {
                    Id           = factRecord.Id,
                    Date         = factRecord.Date,
                    Number       = factRecord.Number,
                    IdPlanRecord = factRecord.PlanRecord.Id
                };
                ViewBag.Title = "Edit fact record";
                return(View("CreateNewFact", model));
            }
            CreateNewFactRecordViewModel modelVM = new CreateNewFactRecordViewModel()
            {
                IdPlanRecord = (int)idPlan
            };

            ViewBag.Title = "Create new fact record";
            return(View(modelVM));
        }