public ActionResult Edit(LocationMappingItem model) { if (ModelState.IsValid) { var data = Mapper.Map <LocationMappingDto>(model); data.ModifiedDate = DateTime.Now; data.ModifiedBy = CurrentUser.USER_ID; try { var exist = _locationMappingBLL.GetLocationMapping().Where(x => (x.Address == null ? "" : x.Address.ToUpper()) == (data.Address == null ? "" : data.Address.ToUpper()) && (x.Basetown == null ? "" : x.Basetown.ToLower()) == (data.Basetown == null ? "" : data.Basetown.ToLower()) && (x.Location == null ? "" : x.Location.ToLower()) == (data.Location == null ? "" : data.Location.ToLower()) && (x.Region == null ? "" : x.Region.ToLower()) == (data.Region == null ? "" : data.Region.ToLower()) && (x.ZoneSales == null ? "" : x.ZoneSales.ToLower()) == (data.ZoneSales == null ? "" : data.ZoneSales.ToLower()) && (x.ZonePriceList == null ? "" : x.ZonePriceList.ToLower()) == (data.ZonePriceList == null ? "" : data.ZonePriceList.ToLower()) && data.IsActive).FirstOrDefault(); if (exist != null) { model.ErrorMessage = "Data Already Exsit"; var Locationlist = _employeeBLL.GetEmployee().Select(x => new { x.CITY }).ToList().Distinct().OrderBy(x => x.CITY); var BasetownList = _employeeBLL.GetEmployee().Select(x => new { x.BASETOWN }).Distinct().ToList().OrderBy(x => x.BASETOWN); model.LocationList = new SelectList(Locationlist, "CITY", "CITY"); model.BasetownList = new SelectList(BasetownList, "BASETOWN", "BASETOWN"); model.MainMenu = _mainMenu; model.CurrentLogin = CurrentUser; return(View(model)); } _locationMappingBLL.Save(data, CurrentUser); _locationMappingBLL.SaveChanges(); } catch (Exception exp) { model.ErrorMessage = exp.Message; var Locationlist = _employeeBLL.GetEmployee().Select(x => new { x.CITY }).ToList().Distinct().OrderBy(x => x.CITY); var BasetownList = _employeeBLL.GetEmployee().Select(x => new { x.BASETOWN }).Distinct().ToList().OrderBy(x => x.BASETOWN); model.LocationList = new SelectList(Locationlist, "CITY", "CITY"); model.BasetownList = new SelectList(BasetownList, "BASETOWN", "BASETOWN"); model.MainMenu = _mainMenu; model.CurrentLogin = CurrentUser; return(View(model)); } } return(RedirectToAction("Index", "MstLocationMapping")); }
public JsonResult UploadFile(HttpPostedFileBase upload) { var data = (new ExcelReader()).ReadExcel(upload); var model = new List <LocationMappingItem>(); if (data != null) { foreach (var dataRow in data.DataRows) { if (dataRow.Count <= 0) { continue; } if (dataRow[0] == "") { continue; } var item = new LocationMappingItem(); item.ErrorMessage = ""; item.Location = dataRow[0].ToString(); if (item.Location == "") { item.ErrorMessage = "Location list Can't be empty"; } item.Address = dataRow[1].ToString(); if (item.Address == "") { item.ErrorMessage = "Address list Can't be empty"; } item.Basetown = dataRow[2].ToString(); if (item.Basetown == "") { item.ErrorMessage = "Basetown list Can't be empty"; } item.Region = dataRow[3].ToString(); item.ZoneSales = dataRow[4].ToString(); item.ZonePriceList = dataRow[5].ToString(); if (item.ZonePriceList == "") { item.ErrorMessage = "Zone Price list Can't be empty"; } try { double dValidfrom = double.Parse(dataRow[6].ToString()); DateTime dtValidfrom = DateTime.FromOADate(dValidfrom); item.ValidFrom = dtValidfrom; item.ErrorMessage = ""; } catch (Exception) { item.ErrorMessage = "Format Date is not Valid"; } var exist = _locationMappingBLL.GetLocationMapping().Where(x => x.Address == item.Address && (x.Basetown == null ? "" : x.Basetown.ToLower()) == (item.Basetown == null ? "" : item.Basetown.ToLower()) && (x.Location == null ? "" : x.Location.ToLower()) == (item.Location == null ? "" : item.Location.ToLower()) && (x.Region == null ? "" : x.Region.ToLower()) == (item.Region == null ? "" : item.Region.ToLower()) && (x.ZoneSales == null ? "" : x.ZoneSales.ToLower()) == (item.ZoneSales == null ? "" : item.ZoneSales.ToLower()) && (x.ZonePriceList == null ? "" : x.ZonePriceList.ToLower()) == (item.ZonePriceList == null ? "" : item.ZonePriceList.ToLower()) && x.IsActive).FirstOrDefault(); if (exist != null) { item.ErrorMessage = "Data Already Exist"; } model.Add(item); } } return(Json(model)); }