public void EditPromotion(PromotionEdit model) { var entity = GetById(model.PromotionId); entity.Summary = model.NewSummary; entity.Details = model.NewDetails; }
// GET: Edit public ActionResult Edit(int id) { var service = CreatePromotionService(); var detail = service.GetPromotionById(id); var model = new PromotionEdit { PromotionId = detail.PromotionId, PromotionName = detail.PromotionName, DateFounded = detail.DateFounded, Website = detail.Website }; return(View(model)); }
public bool UpdatePromotion(PromotionEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx.Promotions.Single(e => e.PromotionId == model.PromotionId && e.OwnerId == _userId); entity.PromotionName = model.PromotionName; //entity.IsStarred = model.IsStarred; entity.DateFounded = model.DateFounded.Date; entity.Website = model.Website; return(ctx.SaveChanges() == 1); } }
private bool SetStarState(int promotionId, bool newState) { //Create the service var userId = Guid.Parse(User.Identity.GetUserId()); var service = new PromotionService(userId); // Get the promotion var detail = service.GetPromotionById(promotionId); // Create the PromotionEdit model instance wih the new star state var updatedPromotion = new PromotionEdit { PromotionId = detail.PromotionId, PromotionName = detail.PromotionName, IsStarred = newState, DateFounded = detail.DateFounded, Website = detail.Website }; //Return a value indicating whether the update succeeded return(service.UpdatePromotion(updatedPromotion)); }
public ActionResult Edit(int id, PromotionEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.PromotionId != id) { ModelState.AddModelError("", "ID Mismatch"); return(View(model)); } var service = CreatePromotionService(); if (service.UpdatePromotion(model)) { TempData["SaveResult"] = "The promotion has been updated!"; return(RedirectToAction("Index")); } ModelState.AddModelError("", "The promotion could not be updated."); return(View(model)); }