public ActionResult AddNew(SaleModel model) { if (ModelState.IsValid) { SaleService salesService = new SaleService(); Sale newSale = salesService.GetNewSale(); MapSaleModelToSale(model, newSale, true); if (salesService.SaveNewSale(newSale)) { model = MapSaleToSaleModel(newSale); return View("Confirm", model); } else { ModelState.AddModelError("", "Could not save sale details."); } } else { ModelState.AddModelError("", "Sale event details are not correct."); } return View(model); }
/// <summary> /// Get a list of sales for a specified date /// </summary> /// <param name="searchDate"></param> /// <returns></returns> private JsonResult GetSalesListByDate(DateTime searchDate) { SaleService salesService = new SaleService(); List<Sale> saleList = salesService.ListSalesByDate(searchDate); if (!string.IsNullOrEmpty(salesService.LastErrorMessage)) { Response.StatusCode = 500; Response.StatusDescription = salesService.LastErrorMessage; return Json(null); } else { List<SaleModel> viewList = saleList.Select(s => MapSaleToSaleModel(s)).ToList(); JavaScriptSerializer js = new JavaScriptSerializer(); SaleListAndSearchDate jsonData = new SaleListAndSearchDate() { SaleList = viewList, SearchDate = searchDate.ToShortDateString() }; return Json(jsonData); } }