public bool UpdatePrice(int id, EventPriceViewModel model) { var price = _unitOfWork.EventPriceRepository.Get(model.Id.Value); if (price == null) { return(false); } price.Name = model.Name; if (model.Total < price.Sold) { return(false); } price.Total = model.Total; if (model.Price != price.Price) { var newPrice = new EventPrice { Name = model.Name, Total = price.Total - price.Sold, Price = model.Price, EventId = price.EventId }; _unitOfWork.EventPriceRepository.Insert(newPrice); price.Total = price.Sold; price.IsRemoved = true; } _unitOfWork.Commit(); return(true); }
public void AddPrice(int id, EventPriceViewModel model) { var price = new EventPrice { Name = model.Name, Total = model.Total, Price = model.Price, EventId = id }; _unitOfWork.EventPriceRepository.Insert(price); _unitOfWork.Commit(); }
public IActionResult SavePrice(int id, EventPriceViewModel currentPrice, string returnUrl) { ViewBag.ReturnUrl = returnUrl; var model = _eventService.GetSingle(id); if (model == null) { return(NotFound()); } if (!ModelState.IsValid) { model.CurrentPrice = currentPrice; return(View("EditEvent", model)); } var ok = true; if (currentPrice.Id.HasValue) { ok = _eventService.UpdatePrice(id, currentPrice); } else { _eventService.AddPrice(id, currentPrice); } if (!ok) { return(NotFound()); } if (!string.IsNullOrEmpty(returnUrl)) { return(Redirect(returnUrl)); } return(View("EditEvent", _eventService.GetSingle(id))); }