public ActionResult UploadManualProduction() { var model = new ProductionUploadViewModel(); model.MainMenu = _mainMenu; model.CurrentMenu = PageInfo; return(View(model)); }
public ActionResult UploadManualProduction(ProductionUploadViewModel model) { var modelDto = Mapper.Map <ProductionDto>(model); try { var listProduction = new List <ProductionUploadItems>(); //check validation foreach (var item in modelDto.UploadItems) { var company = _companyBll.GetById(item.CompanyCode); var plant = _plantBll.GetT001WById(item.PlantWerks); var brandCe = _brandRegistrationBll.GetByFaCode(item.PlantWerks, item.FaCode); if (brandCe == null) { continue; } if (brandCe.IS_DELETED == true || (brandCe.STATUS == false || brandCe.STATUS == null)) { //AddMessageInfo("Data Brand Description Is Inactive", Enums.MessageInfoType.Error); //return RedirectToAction("UploadManualProduction"); continue; } item.QtyPacked = "0"; if (item.Uom == "TH") { item.Uom = "Btg"; //item.QtyPacked = Convert.ToString(Convert.ToDecimal(item.QtyPacked) * 1000); item.Qty = Convert.ToString(Convert.ToDecimal(item.Qty) * 1000); item.Zb = Convert.ToDecimal(item.Zb) * 1000; } if (item.Uom == "KG") { item.Uom = "G"; item.QtyPacked = Convert.ToString(Convert.ToDecimal(item.QtyPacked) * 1000); item.Qty = Convert.ToString(Convert.ToDecimal(item.Qty) * 1000); item.PackedAdjusted = item.PackedAdjusted * 1000; } item.CompanyName = company.BUTXT; item.PlantName = plant.NAME1; if (item.BrandDescription != brandCe.BRAND_CE) { //AddMessageInfo("Data Brand Description Is Not valid", Enums.MessageInfoType.Error); //return RedirectToAction("UploadManualProduction"); continue; } item.CreatedDate = DateTime.Now; item.CreatedBy = CurrentUser.USER_ID; var existingData = _productionBll.GetExistDto(item.CompanyCode, item.PlantWerks, item.FaCode, Convert.ToDateTime(item.ProductionDate)); if (existingData != null) { //AddMessageInfo("Data Already Exist, Please Check Data Company Code," + // " Plant Code, Fa Code, and Waste Production Date", Enums.MessageInfoType.Warning); //return RedirectToAction("UploadManualProduction"); var existItem = Mapper.Map <ProductionUploadItems>(existingData); existItem.Qty = item.Qty; existItem.PackedAdjusted = item.PackedAdjusted; existItem.Zb = item.Zb; existItem.Remark = item.Remark; existItem.ModifiedDate = DateTime.Now; existItem.ModifiedBy = CurrentUser.USER_ID; listProduction.Add(existItem); continue; } listProduction.Add(item); } //do save foreach (var data in listProduction) { _productionBll.SaveUpload(data, CurrentUser.USER_ID); } if (listProduction.Count == 0) { AddMessageInfo("Error, Data is not Valid", Enums.MessageInfoType.Error); } else { AddMessageInfo(Constans.SubmitMessage.Saved, Enums.MessageInfoType.Success); } } catch (Exception) { AddMessageInfo("Error, Data is not Valid", Enums.MessageInfoType.Error); return(RedirectToAction("UploadManualProduction")); } return(RedirectToAction("Index")); }