public ActionResult EditChar(ShopProductChar model) { model.IsPost = true; if (model.Name.IsNullOrEmpty()) { return(View(model)); } if (model.ID == 0) { model.UserID = CurrentUser.ShopOwnerID; DB.ShopProductChars.InsertOnSubmit(model); Logger.WriteEvent( model.ShopID.HasValue ? Logger.EventType.ShopCharAdd : Logger.EventType.ShopCharCommonAdd, "Добавление характеристики " + model.Name + (model.ShopID.HasValue ? (" для магазина " + DB.Shops.First(x => x.ID == model.ShopID).Name) : "")); } else { var ch = DB.ShopProductChars.FirstOrDefault(x => x.ID == model.ID && x.UserID == CurrentUser.ShopOwnerID); if (ch != null) { ch.LoadPossibleProperties(model, new[] { "ID", "UserID" }); } Logger.WriteEvent( model.ShopID.HasValue ? Logger.EventType.ShopCharEdit : Logger.EventType.ShopCharCommonEdit, "Редактирование характеристики " + model.Name + (model.ShopID.HasValue ? (" для магазина " + DB.Shops.First(x => x.ID == model.ShopID).Name) : "")); } DB.SubmitChanges(); return(RedirectToAction("Chars", new { ShopID = model.ShopID })); }
public ActionResult EditChar(int?ShopID, int?ID) { if (ID.HasValue) { var ch = DB.ShopProductChars.FirstOrDefault(x => x.ID == ID && x.UserID == CurrentUser.ShopOwnerID); if (ch != null) { return(View(ch)); } else { return(RedirectToAction("Chars")); } } else { var ch = new ShopProductChar() { ShopID = ShopID }; return(View(ch)); } }