public ActionResult Create(CostObItem item) { string year = Request.Params["Year"]; if (ModelState.IsValid) { var data = Mapper.Map <CostObDto>(item); data.CreatedBy = CurrentUser.USER_ID; data.CreatedDate = DateTime.Now; data.IsActive = true; try { _costObBLL.Save(data); } catch (Exception ex) { item.ErrorMessage = ex.Message; item.MainMenu = _mainMenu; item.CurrentLogin = CurrentUser; item = InitialModel(item); return(View(item)); } } return(RedirectToAction("Index", "MstCostOb")); }
public ActionResult Create() { var model = new CostObItem(); model.MainMenu = _mainMenu; model.CurrentLogin = CurrentUser; model = InitialModel(model); model.ObCost = null; model.Year = null; return(View(model)); }
public ActionResult Detail(int MstCostObid) { var data = _costObBLL.GetByID(MstCostObid); var model = new CostObItem(); model = Mapper.Map <CostObItem>(data); model.MainMenu = _mainMenu; model.CurrentLogin = CurrentUser; model = InitialModel(model); model.ChangesLogs = GetChangesHistory((int)Enums.MenuList.MasterCostOB, MstCostObid); return(View(model)); }
public ActionResult Edit(int?MstCostObid) { if (!MstCostObid.HasValue) { return(HttpNotFound()); } var data = _costObBLL.GetByID(MstCostObid.Value); var model = new CostObItem(); model = Mapper.Map <CostObItem>(data); model.MainMenu = _mainMenu; model.CurrentLogin = CurrentUser; model = InitialModel(model); model.ChangesLogs = GetChangesHistory((int)Enums.MenuList.MasterCostOB, MstCostObid.Value); return(View(model)); }
public ActionResult Edit(CostObItem item) { if (ModelState.IsValid) { var data = Mapper.Map <CostObDto>(item); data.ModifiedDate = DateTime.Now; data.ModifiedBy = CurrentUser.USER_ID; try { _costObBLL.Save(data, CurrentUser); } catch (Exception ex) { item.ErrorMessage = ex.Message; item.MainMenu = _mainMenu; item.CurrentLogin = CurrentUser; item = InitialModel(item); } } return(RedirectToAction("Index", "MstCostOb")); }
public JsonResult UploadFile(HttpPostedFileBase upload) { var data = (new ExcelReader()).ReadExcel(upload); var model = new List <CostObItem>(); if (data != null) { foreach (var dataRow in data.DataRows) { if (dataRow.Count <= 4) { continue; } if (dataRow[5] == "") { continue; } var item = new CostObItem(); item.ErrorMessage = ""; try { for (int i = 5; i <= data.Headers.Count() - 1; i++) { item = new CostObItem(); item.ErrorMessage = ""; item.CostCenter = dataRow[0]; if (item.CostCenter == "") { item.ErrorMessage = "Cost Center can't be empty"; } item.FunctionName = dataRow[1]; if (item.FunctionName == "") { item.ErrorMessage = "Function Can't be empty"; } item.Regional = dataRow[2]; item.VehicleType = dataRow[3]; if (item.VehicleType == "") { item.ErrorMessage = "Vehicle Type Can't be empty"; } if (data.Headers[i] == "" || data.Headers[i] == null) { continue; } var Header = data.Headers[i].Split('_'); if (Header.Count() > 1) { var Type = Header[0]; item.Type = ""; item.ObCost = null; item.Qty = null; var Time = Header[1].Split('-'); if (Time.Count() > 1) { if (Type.ToUpper() == "QTY") { item.Type = "QTY"; try { item.Qty = Convert.ToInt32(dataRow[i]); } catch (Exception) { item.ErrorMessage = "Qty must be number"; } item.Month = Convert.ToInt32(Time[0]); item.Year = Convert.ToInt32(Time[1]); model.Add(item); } else { item.Type = Type; try { item.ObCost = Convert.ToDecimal(dataRow[i]); } catch (Exception) { item.ErrorMessage = "Cost OB must be number"; } item.Month = Convert.ToInt32(Time[0]); item.Year = Convert.ToInt32(Time[1]); model.Add(item); } } } } } catch (Exception ex) { item.ErrorMessage = ex.Message; } } } if (model.Where(x => x.ErrorMessage != null && x.ErrorMessage != "").ToList().Count > 0) { model = model.Where(x => x.ErrorMessage != null && x.ErrorMessage != "").ToList(); return(Json(model)); } else { return(Json(model)); } }
public CostObItem InitialModel(CostObItem model) { var ZoneList = _locationMappingBLL.GetLocationMapping().Where(x => x.IsActive == true).ToList(); model.ZoneList = new SelectList(ZoneList, "ZonePriceList", "ZonePriceList"); var ModelList = new List <SelectListItem> { new SelectListItem { Text = "MPV", Value = "MPV" }, new SelectListItem { Text = "SUV", Value = "SUV" }, new SelectListItem { Text = "Forklift", Value = "Forklift" }, new SelectListItem { Text = "Motorcycle", Value = "Motorcycle" }, new SelectListItem { Text = "Truck", Value = "Truck" } }; model.ModelList = new SelectList(ModelList, "Value", "Text"); var TypeList = new List <SelectListItem> { new SelectListItem { Text = "Benefit", Value = "Benefit" }, new SelectListItem { Text = "WTC", Value = "WTC" }, }; model.TypeList = new SelectList(TypeList, "Value", "Text"); var MonthList = new List <SelectListItem>() { new SelectListItem() { Text = "January", Value = "1" }, new SelectListItem() { Text = "February", Value = "2" }, new SelectListItem() { Text = "March", Value = "3" }, new SelectListItem() { Text = "April", Value = "4" }, new SelectListItem() { Text = "May", Value = "5" }, new SelectListItem() { Text = "June", Value = "6" }, new SelectListItem() { Text = "July", Value = "7" }, new SelectListItem() { Text = "August", Value = "8" }, new SelectListItem() { Text = "September", Value = "9" }, new SelectListItem() { Text = "October", Value = "10" }, new SelectListItem() { Text = "November", Value = "11" }, new SelectListItem() { Text = "December", Value = "12" } }; model.MonthList = new SelectList(MonthList, "Value", "Text"); return(model); }
public ActionResult Upload(CostObModel Model) { var data = (new ExcelReader()).ReadExcel(Model.upload); var model = new List <CostObItem>(); if (data != null) { foreach (var dataRow in data.DataRows) { if (dataRow.Count <= 4) { continue; } if (dataRow[5] == "") { continue; } var item = new CostObItem(); item.ErrorMessage = ""; try { for (int i = 5; i <= data.Headers.Count() - 1; i++) { item = new CostObItem(); item.ErrorMessage = ""; item.CostCenter = dataRow[0]; if (item.CostCenter == "") { item.ErrorMessage = "Cost Center can't be empty"; } item.FunctionName = dataRow[1]; if (item.FunctionName == "") { item.ErrorMessage = "Function Can't be empty"; } item.Regional = dataRow[2]; item.VehicleType = dataRow[3]; if (item.VehicleType == "") { item.ErrorMessage = "Vehicle Type Can't be empty"; } if (data.Headers[i] == "" || data.Headers[i] == null) { continue; } var Header = data.Headers[i].Split('_'); if (Header.Count() > 1) { var Type = Header[0]; item.Type = ""; item.ObCost = null; item.Qty = null; var Time = Header[1].Split('-'); if (Time.Count() > 1) { if (Type.ToUpper() == "QTY") { item.Type = "QTY"; try { item.Qty = Convert.ToInt32(dataRow[i]); } catch (Exception) { item.ErrorMessage = "Qty must be number"; } item.Month = Convert.ToInt32(Time[0]); item.Year = Convert.ToInt32(Time[1]); var exist = _costObBLL.GetCostOb().Where(x => (x.FunctionName == null ? "" : x.FunctionName.ToUpper()) == (item.FunctionName == null ? "" : item.FunctionName.ToUpper()) && (x.CostCenter == null ? "" : x.CostCenter.ToUpper()) == (item.CostCenter == null ? "" : item.CostCenter.ToUpper()) && (x.Regional == null ? "" : x.Regional.ToUpper()) == (item.Regional == null ? "" : item.Regional.ToUpper()) && (x.VehicleType == null ? "" : x.VehicleType.ToUpper()) == (item.VehicleType == null ? "" : item.VehicleType.ToUpper()) && (x.Type == null ? "" : x.Type.ToUpper()) == (item.Type == null ? "" : item.Type.ToUpper()) && x.Month == item.Month && x.Year == item.Year && x.IsActive).FirstOrDefault(); if (exist != null) { exist.IsActive = false; exist.ModifiedBy = "SYSTEM"; exist.ModifiedDate = DateTime.Now; _costObBLL.Save(exist); } var dto = Mapper.Map <CostObDto>(item); dto.CreatedBy = CurrentUser.USER_ID; dto.CreatedDate = DateTime.Now; dto.IsActive = true; _costObBLL.Save(dto); } else { item.Type = Type; try { item.ObCost = Convert.ToDecimal(dataRow[i]); } catch (Exception) { item.ErrorMessage = "Cost OB must be number"; } item.Month = Convert.ToInt32(Time[0]); item.Year = Convert.ToInt32(Time[1]); var exist = _costObBLL.GetCostOb().Where(x => (x.FunctionName == null ? "" : x.FunctionName.ToUpper()) == (item.FunctionName == null ? "" : item.FunctionName.ToUpper()) && (x.CostCenter == null ? "" : x.CostCenter.ToUpper()) == (item.CostCenter == null ? "" : item.CostCenter.ToUpper()) && (x.Regional == null ? "" : x.Regional.ToUpper()) == (item.Regional == null ? "" : item.Regional.ToUpper()) && (x.VehicleType == null ? "" : x.VehicleType.ToUpper()) == (item.VehicleType == null ? "" : item.VehicleType.ToUpper()) && (x.Type == null ? "" : x.Type.ToUpper()) == (item.Type == null ? "" : item.Type.ToUpper()) && x.Month == item.Month && x.Year == item.Year && x.IsActive).FirstOrDefault(); if (exist != null) { exist.IsActive = false; exist.ModifiedBy = "SYSTEM"; exist.ModifiedDate = DateTime.Now; _costObBLL.Save(exist); } var dto = Mapper.Map <CostObDto>(item); dto.CreatedBy = CurrentUser.USER_ID; dto.CreatedDate = DateTime.Now; dto.IsActive = true; _costObBLL.Save(dto); } } } } } catch (Exception ex) { item.ErrorMessage = ex.Message; } } try { _costObBLL.SaveChanges(); } catch (Exception exp) { Model.ErrorMessage = exp.Message; Model.MainMenu = _mainMenu; Model.CurrentLogin = CurrentUser; return(View(Model)); } } return(RedirectToAction("Index", "MstCostOb")); }