/// <summary> /// Save Data /// </summary> /// <param name="regionSale"></param> /// <returns></returns> public void save(RegionSale regionSale) { RegionSale regionSaleDB = getById(regionSale.MonthId, regionSale.StateId); if (regionSaleDB != null) { regionSaleDB.Sales = regionSale.Sales; Update(regionSaleDB); } else { Insert(regionSale); } }
public ActionResult Save(RegionSaleModel model) { if (ModelState.IsValid) { RegionSale regionSale = new RegionSale(); regionSale.MonthId = model.MonthId; regionSale.StateId = model.StateId; regionSale.Sales = model.Sales; regionSaleService.save(regionSale); } return(RedirectToAction("Index")); }
/// <summary> /// Get Median list of all month state vise /// </summary> /// <returns>List of Median</returns> private List <int> getMediaList() { List <int> result = new List <int>(); foreach (State state in StateList) { int[] monthList1 = new int[12]; foreach (Month month in MonthList) { RegionSale model = RegionSaleList.AsEnumerable().Where(rs => rs.StateId == state.Id && rs.MonthId == month.Id).FirstOrDefault(); monthList1[month.Id - 1] = model == null ? 0: model.Sales; } Array.Sort(monthList1); result.Add((monthList1[(monthList1.Length / 2) - 1] + monthList1[monthList1.Length / 2]) / 2); } return(result); }
/// <summary> /// Update Data /// </summary> /// <param name="regionSale"></param> /// <returns></returns> public void Update(RegionSale regionSale) { _entities.Entry(regionSale).State = EntityState.Modified; _entities.SaveChanges(); }
/// <summary> /// Insert Data /// </summary> /// <param name="regionSale"></param> /// <returns></returns> public void Insert(RegionSale regionSale) { _entities.RegionSales.Add(regionSale); _entities.SaveChanges(); }