public ActionResult Edit(int id) { using (var db = new StudentEntiy()) { ViewBag.Type = Gtype(); ViewBag.Studio = Studio(); var model = db.Game.FirstOrDefault(s => s.id == id); if (model != null) { var viewModel = new EditListViewModel() { id = model.id, gName = model.gName, gTid = model.gTid, gSid = model.gSId, gPrice = model.gPrice, gState = model.gState }; return(View(viewModel)); } else { return(HttpNotFound()); } } }
public ActionResult Edit(EditListViewModel viewModel) { //模型验证 if (ModelState.IsValid) { //上下文 using (var db = new StudentEntiy()) { //查询出当前列信息 var model = db.Game.FirstOrDefault(s => s.id == viewModel.id); if (model != null) { model.gName = viewModel.gName; model.gTid = viewModel.gTid; model.gSId = viewModel.gSid; model.gPrice = viewModel.gPrice; model.gState = viewModel.gState; //提交 db.SaveChanges(); ViewBag.SaveMsg = "修改成功!"; } } } else { //编辑失败信息 ModelState.AddModelError("", "失败!请检查信息完整性!"); } ViewBag.Type = Gtype(); ViewBag.Studio = Studio(); return(View(viewModel)); }
public ActionResult Edit(EditListViewModel editList, int edit) { if (editList.AccountIds == null) { ModelState.AddModelError("Members", "The list must contain at least one member."); return(this.View("_EditListModal", editList)); } else { // TODO: This is NOT correct. There should be *TWO* distinct methods Edit and Create. //TODO : Check whether or not currentAccount is authorized to edit this list IListModel list = null; list = edit == 0 ? this.Storage.Lists.Create( this.CurrentAccount, editList.ListName, editList.ListDescription, !editList.ListPublic) : this.Storage.Lists.Find(editList.ListId); if (list == null) { throw new HttpException((int)HttpStatusCode.NotFound, "The list doesn't exists."); } try { list.Name = editList.ListName; list.Description = editList.ListDescription; list.IsPrivate = !editList.ListPublic; list.Members.Clear(); foreach (var member in editList.AccountIds) { IAccountModel account = this.Storage.Accounts.Find(member); list.Members.Add(account); } this.Storage.SaveChanges(); return(this.RedirectToAction("Index", "Home")); } catch (Models.Storage.AccountNotFoundException ex) { if (edit == 0) { this.Storage.Lists.Delete(list); } throw new HttpException((int)HttpStatusCode.NotFound, ex.Message); } catch (Tigwi.Storage.Library.IsPersonnalList ex) { return(this.RedirectToAction("Index", "Home", new { error = ex.Message })); } } }
public ActionResult Edit(EditListViewModel viewModel) { if (!ModelState.IsValid) { return(View(viewModel)); } try { ListService.UpdateListByListId(viewModel.ListId, viewModel); } catch { throw; } return(RedirectToAction("Details", new { listId = viewModel.ListId })); }
public ActionResult Edit(EditListViewModel editList, int edit) { if (editList.AccountIds == null) { ModelState.AddModelError("Members", "The list must contain at least one member."); return this.View("_EditListModal", editList); } else { // TODO: This is NOT correct. There should be *TWO* distinct methods Edit and Create. //TODO : Check whether or not currentAccount is authorized to edit this list IListModel list = null; list = edit == 0 ? this.Storage.Lists.Create( this.CurrentAccount, editList.ListName, editList.ListDescription, !editList.ListPublic) : this.Storage.Lists.Find(editList.ListId); if (list == null) throw new HttpException((int)HttpStatusCode.NotFound, "The list doesn't exists."); try { list.Name = editList.ListName; list.Description = editList.ListDescription; list.IsPrivate = !editList.ListPublic; list.Members.Clear(); foreach (var member in editList.AccountIds) { IAccountModel account = this.Storage.Accounts.Find(member); list.Members.Add(account); } this.Storage.SaveChanges(); return this.RedirectToAction("Index", "Home"); } catch (Models.Storage.AccountNotFoundException ex) { if (edit == 0) this.Storage.Lists.Delete(list); throw new HttpException((int)HttpStatusCode.NotFound, ex.Message); } catch (Tigwi.Storage.Library.IsPersonnalList ex) { return this.RedirectToAction("Index", "Home", new { error = ex.Message }); } } }
public void UpdateListByListId(Guid listId, EditListViewModel list) { try { var result = FilmHausDbContext.Lists.Find(listId); if (result == null) { throw new KeyNotFoundException(); } result.Description = list.Description; result.Shared = list.Shared; FilmHausDbContext.Entry(result).State = EntityState.Modified; FilmHausDbContext.SaveChanges(); } catch (InvalidOperationException ex) { throw ex; } }