public ActionResult Create(PriceCreateViewModel model, string redirectUrl) { if (!ModelState.IsValid) { return(View(model)); } List <Prices> prices = Price.Get().Where(t => t.ServicesId == model.ServiceSelected).ToList().Where(p => p.FromDate <= model.FromDate && (p.ToDate > model.FromDate || p.ToDate == null)).ToList(); if (prices.Count != 0) { prices[0].ToDate = model.FromDate; Price.Update(prices[0]); } var price = new Prices { ServicesId = model.ServiceSelected, ToDate = null, Value = model.Value, FromDate = model.FromDate }; if (prices.Count == 2) { price.ToDate = prices[1].FromDate; } Price.Create(price); return(RedirectToLocal(redirectUrl)); }
public ActionResult Create() { var services = Services.Get().Select(s => new SelectListItem { Text = s.Name, Value = Convert.ToString(s.ServicesId) }).ToList(); var model = new PriceCreateViewModel { Service = services }; return(View(model)); }