コード例 #1
0
        public ActionResult Create(EditableMigraineViewModel migraineViewModel)
        {
            if (ModelState.IsValid)
            {
                var migraineModel = migraineViewModel.ToMigraineModel();
                //migraineModel.ID = Guid.NewGuid();
                DataContext.Migraines.Add(migraineModel);
                DataContext.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(migraineViewModel);
        }
コード例 #2
0
        public ActionResult Edit(EditableMigraineViewModel migraineViewModel)
        {
            if (ModelState.IsValid)
            {
                var modelUpdates = migraineViewModel.ToMigraineModel();

                var migraineModel = HelperMethods.FindFromGuid(DataContext, migraineViewModel.ID.ToString());
                migraineModel.Update(modelUpdates);

                DataContext.Entry(migraineModel).State = EntityState.Modified;
                try
                {
                    DataContext.SaveChanges();
                }
                catch (Exception)
                {
                    DataContext.Entry(migraineModel).Reload();
                    DataContext.SaveChanges();
                    //DataContext.Refresh(RefreshMode.ClientWins, DataContext.Migraines);
                    //DataContext.SaveChanges();
                }
                return RedirectToAction("Index");
            }
            return View(migraineViewModel);
        }