//public WasteStockDto GetExisWasteStockByWerksAndMaterial(string werks, string materialNumber) //{ // var dbdata = _uow.GetGenericRepository<WASTE_STOCK>().Get(p => p.WERKS == werks && p.MATERIAL_NUMBER == materialNumber).FirstOrDefault(); // return Mapper.Map<WasteStockDto>(dbdata); //} public void UpdateWasteStockFromWaste(WasteStockDto input, string userId) { var dbWasteStock = _repository.Get(c => c.WERKS == input.WERKS && c.MATERIAL_NUMBER == input.MATERIAL_NUMBER) .FirstOrDefault(); var origin = Mapper.Map <WasteStockDto>(dbWasteStock); if (dbWasteStock == null) { dbWasteStock = new WASTE_STOCK(); Mapper.Map <WasteStockDto, WASTE_STOCK>(input, dbWasteStock); dbWasteStock.CREATED_BY = input.CREATED_BY; dbWasteStock.CREATED_DATE = DateTime.Now; } else { //update dbWasteStock.STOCK = input.STOCK; dbWasteStock.MODIFIED_BY = input.CREATED_BY; dbWasteStock.MODIFIED_DATE = DateTime.Now; var dbData = _repository.GetByID(dbWasteStock.WASTE_STOCK_ID); var inputNew = Mapper.Map <WasteStockDto>(dbData); if (inputNew.WASTE_STOCK_ID > 0) { SetChangesHistory(origin, inputNew, userId); } } _repository.InsertOrUpdate(dbWasteStock); }
private bool SetChangesHistory(WasteStockDto origin, WasteStockDto data, string userId) { bool isModified = false; var changesData = new Dictionary <string, bool>(); changesData.Add("PLANT_ID", origin.WERKS == data.WERKS); changesData.Add("MATERIAL_NUMBER", origin.MATERIAL_NUMBER == data.MATERIAL_NUMBER); changesData.Add("STOCK", origin.STOCK == data.STOCK); foreach (var listChange in changesData) { if (listChange.Value) { continue; } var changes = new CHANGES_HISTORY(); changes.FORM_TYPE_ID = Enums.MenuList.WasteStock; changes.FORM_ID = origin.WASTE_STOCK_ID.ToString(); changes.FIELD_NAME = listChange.Key; changes.MODIFIED_BY = userId; changes.MODIFIED_DATE = DateTime.Now; switch (listChange.Key) { case "PLANT_ID": changes.OLD_VALUE = origin.WERKS; changes.NEW_VALUE = data.WERKS; break; case "MATERIAL_NUMBER": changes.OLD_VALUE = origin.MATERIAL_NUMBER; changes.NEW_VALUE = data.MATERIAL_NUMBER; break; case "STOCK": changes.OLD_VALUE = ConvertHelper.ConvertDecimalToStringMoneyFormat(origin.STOCK); changes.NEW_VALUE = ConvertHelper.ConvertDecimalToStringMoneyFormat(data.STOCK); break; } _changesHistoryBll.AddHistory(changes); isModified = true; } return(isModified); }
private void UpdateWasteStockTable(WASTE dbWaste, string userId, bool isNewData) { var dbdata = GetAllByParam(new WasteGetByParamInput { Plant = dbWaste.WERKS }); var dbQtyWaste = CalculateWasteQuantity(dbdata); if (dbQtyWaste != null) { var listWasteStockDto = new List <WasteStockDto>(); decimal?updateValueFloor = dbQtyWaste.FloorWasteGramQty; decimal?updateValueDust = dbQtyWaste.DustWasteGramQty; decimal?updateValueStamp = dbQtyWaste.StampWasteQty; //if (isNewData && dbQtyWaste.PlantWerks == dbWaste.WERKS) //{ // updateValueFloor = dbQtyWaste.FloorWasteGramQty + dbWaste.FLOOR_WASTE_GRAM_QTY; // updateValueDust = dbQtyWaste.DustWasteGramQty + dbWaste.DUST_WASTE_GRAM_QTY; // updateValueStamp = dbQtyWaste.StampWasteQty + dbWaste.STAMP_WASTE_QTY; //} var wasStockWsapoon = new WasteStockDto(); wasStockWsapoon.WERKS = dbQtyWaste.PlantWerks; wasStockWsapoon.MATERIAL_NUMBER = Constans.WasteFloor; wasStockWsapoon.STOCK = Convert.ToDecimal(updateValueFloor); wasStockWsapoon.CREATED_BY = userId; listWasteStockDto.Add(wasStockWsapoon); var wasteStockGagang = new WasteStockDto(); wasteStockGagang.WERKS = dbQtyWaste.PlantWerks; wasteStockGagang.MATERIAL_NUMBER = Constans.WasteDust; wasteStockGagang.STOCK = Convert.ToDecimal(updateValueDust); wasteStockGagang.CREATED_BY = userId; listWasteStockDto.Add(wasteStockGagang); var wasteStockStem = new WasteStockDto(); wasteStockStem.WERKS = dbQtyWaste.PlantWerks; wasteStockStem.MATERIAL_NUMBER = Constans.WasteStem; wasteStockStem.STOCK = Convert.ToDecimal(updateValueStamp); wasteStockStem.CREATED_BY = userId; listWasteStockDto.Add(wasteStockStem); foreach (var wasteStockDto in listWasteStockDto) { //CHECK ON MATERIAL PLANT AND STICKER CODE EXIST var dbMaterial = _materialBll.GetByPlantIdAndStickerCode(wasteStockDto.WERKS, wasteStockDto.MATERIAL_NUMBER); if (dbMaterial == null) { throw new BLLException(ExceptionCodes.BLLExceptions.PlantInWasteNotHaveStickerCode); } else { _wasteStockBll.UpdateWasteStockFromWaste(wasteStockDto, userId); } } } }