public bool Save(WasteDto wasteDto, string userId) { var isNewData = true; #region ------get description code----- var company = _companyBll.GetById(wasteDto.CompanyCode); var plant = _plantBll.GetT001WById(wasteDto.PlantWerks); var brandDesc = _brandRegistrationBll.GetById(wasteDto.PlantWerks, wasteDto.FaCode); wasteDto.CompanyName = company.BUTXT; wasteDto.PlantName = plant.NAME1; wasteDto.BrandDescription = brandDesc.BRAND_CE; #endregion var dbWaste = Mapper.Map <WASTE>(wasteDto); dbWaste.MARKER_REJECT_STICK_QTY = wasteDto.MarkerStr == null ? 0 : Convert.ToDecimal(wasteDto.MarkerStr); dbWaste.PACKER_REJECT_STICK_QTY = wasteDto.PackerStr == null ? 0 : Convert.ToDecimal(wasteDto.PackerStr); dbWaste.DUST_WASTE_GRAM_QTY = wasteDto.DustGramStr == null ? 0 : Convert.ToDecimal(wasteDto.DustGramStr); dbWaste.FLOOR_WASTE_GRAM_QTY = wasteDto.FloorGramStr == null ? 0 : Convert.ToDecimal(wasteDto.FloorGramStr); dbWaste.DUST_WASTE_STICK_QTY = wasteDto.DustStickStr == null ? 0 : Convert.ToDecimal(wasteDto.DustStickStr); dbWaste.FLOOR_WASTE_STICK_QTY = wasteDto.FloorStickStr == null ? 0 : Convert.ToDecimal(wasteDto.FloorStickStr); dbWaste.STAMP_WASTE_QTY = wasteDto.StampWasteQtyStr == null ? 0 : Convert.ToDecimal(wasteDto.StampWasteQtyStr); var origin = _repository.GetByID(wasteDto.CompanyCodeX, wasteDto.PlantWerksX, wasteDto.FaCodeX, wasteDto.WasteProductionDateX); var originDto = Mapper.Map <WasteDto>(origin); dbWaste.CREATED_BY = userId; dbWaste.CREATED_DATE = DateTime.Now; if (originDto != null) { SetChange(originDto, wasteDto, userId); isNewData = false; } _repository.InsertOrUpdate(dbWaste); _uow.SaveChanges(); //update waste stock table UpdateWasteStockTable(dbWaste, userId, isNewData); _uow.SaveChanges(); return(isNewData); }
private bool SetChange(WasteDto origin, WasteDto data, string userId) { bool isModified = false; var changeData = new Dictionary <string, bool>(); changeData.Add("COMPANY_CODE", origin.CompanyCode == data.CompanyCode); changeData.Add("WERKS", origin.PlantWerks == data.PlantWerks); changeData.Add("FA_CODE", origin.FaCode == data.FaCode); changeData.Add("WASTE_DATE", origin.WasteProductionDate == data.WasteProductionDate); changeData.Add("BRAND_DESC", origin.BrandDescription == data.BrandDescription); changeData.Add("PLANT_NAME", origin.PlantName == data.PlantName); changeData.Add("COMPANY_NAME", origin.CompanyName == data.CompanyName); changeData.Add("MARKER_REJECT_STICK_QTY", origin.MarkerRejectStickQty == Convert.ToDecimal(data.MarkerStr)); changeData.Add("PACKER_REJECT_STICK_QTY", origin.PackerRejectStickQty == Convert.ToDecimal(data.PackerStr)); changeData.Add("DUST_WASTE_GRAM_QTY", origin.DustWasteGramQty == Convert.ToDecimal(data.DustGramStr)); changeData.Add("FLOOR_WASTE_GRAM_QTY", origin.FloorWasteGramQty == Convert.ToDecimal(data.FloorGramStr)); //changeData.Add("DUST_WASTE_STICK_QTY", origin.DustWasteStickQty == data.DustWasteStickQty); //changeData.Add("FLOOR_WASTE_STICK_QTY", origin.FloorWasteStickQty == data.FloorWasteStickQty); changeData.Add("STAMP_WASTE_QTY", origin.StampWasteQty == Convert.ToDecimal(data.StampWasteQtyStr)); foreach (var listChange in changeData) { if (listChange.Value) { continue; } { var changes = new CHANGES_HISTORY() { FORM_TYPE_ID = Core.Enums.MenuList.CK4C, FORM_ID = "Waste_" + data.CompanyCode + "_" + data.PlantWerks + "_" + data.FaCode + "_" + data.WasteProductionDate.ToString("ddMMMyyyy"), FIELD_NAME = listChange.Key, MODIFIED_BY = userId, MODIFIED_DATE = DateTime.Now }; switch (listChange.Key) { case "COMPANY_CODE": changes.OLD_VALUE = origin.CompanyCode; changes.NEW_VALUE = data.CompanyCode; changes.FIELD_NAME = "Company"; break; case "WERKS": changes.OLD_VALUE = origin.PlantWerks; changes.NEW_VALUE = data.PlantWerks; changes.FIELD_NAME = "Plant"; break; case "FA_CODE": changes.OLD_VALUE = origin.FaCode; changes.NEW_VALUE = data.FaCode; changes.FIELD_NAME = "Finish Goods"; break; case "WASTE_DATE": changes.OLD_VALUE = origin.WasteProductionDate.ToString(); changes.NEW_VALUE = data.WasteProductionDate.ToString(); changes.FIELD_NAME = "Waste Production Date"; break; case "BRAND_DESC": changes.OLD_VALUE = origin.BrandDescription; changes.NEW_VALUE = data.BrandDescription; changes.FIELD_NAME = "Brand Description"; break; case "PLANT_NAME": changes.OLD_VALUE = origin.PlantName; changes.NEW_VALUE = data.PlantName; changes.FIELD_NAME = "Plant"; break; case "COMPANY_NAME": changes.OLD_VALUE = origin.CompanyName; changes.NEW_VALUE = data.CompanyName; changes.FIELD_NAME = "Company"; break; case "MARKER_REJECT_STICK_QTY": changes.OLD_VALUE = origin.MarkerRejectStickQty.ToString(); changes.NEW_VALUE = data.MarkerStr; changes.FIELD_NAME = "Maker Reject Cigarette(stick)"; break; case "PACKER_REJECT_STICK_QTY": changes.OLD_VALUE = origin.PackerRejectStickQty.ToString(); changes.NEW_VALUE = data.PackerStr; changes.FIELD_NAME = "Packer Reject Cigarette(stick)"; break; case "DUST_WASTE_GRAM_QTY": changes.OLD_VALUE = origin.DustWasteGramQty.ToString(); changes.NEW_VALUE = data.DustGramStr; changes.FIELD_NAME = "Dust Waste QTY (gram)"; break; case "FLOOR_WASTE_GRAM_QTY": changes.OLD_VALUE = origin.FloorWasteGramQty.ToString(); changes.NEW_VALUE = data.FloorGramStr; changes.FIELD_NAME = "Floor Waste QTY (gram)"; break; //case "DUST_WASTE_STICK_QTY": // changes.OLD_VALUE = origin.DustWasteStickQty.ToString(); // changes.NEW_VALUE = data.DustWasteStickQty.ToString(); // changes.FIELD_NAME = "Dust Waste QTY (Stick)"; // break; //case "FLOOR_WASTE_STICK_QTY": // changes.OLD_VALUE = origin.FloorWasteStickQty.ToString(); // changes.NEW_VALUE = data.FloorWasteStickQty.ToString(); // changes.FIELD_NAME = "Floor Waste QTY (Stick)"; // break; case "STAMP_WASTE_QTY": changes.OLD_VALUE = origin.StampWasteQty.ToString(); changes.NEW_VALUE = data.StampWasteQtyStr; break; default: break; } _changesHistoryBll.AddHistory(changes); isModified = true; } } return(isModified); }