public ResponseResult CreateOrUpdate(StorageOfSupplementaryMaterialItem model) { if (!string.IsNullOrEmpty(model.F15_SubMaterialCode)) { var lstSupMtrStk = _unitOfWork.SupMaterialStockRepository.GetById(model.F15_SubMaterialCode); if (lstSupMtrStk != null) { lstSupMtrStk.F46_Comment = model.Comment; lstSupMtrStk.F46_Amount = model.IsStore ? lstSupMtrStk.F46_Amount + model.AddQuantity : model.InventoryQuantity; lstSupMtrStk.F46_UpdateDate = DateTime.Now; var entity = Mapper.Map <TX46_SupMtrStk>(lstSupMtrStk); _unitOfWork.SupMaterialStockRepository.Update(entity); } else { var entity = new TX46_SupMtrStk(); entity.F46_AddDate = DateTime.Now; entity.F46_SubMaterialCode = model.F15_SubMaterialCode; entity.F46_Comment = model.Comment; entity.F46_StorageDate = DateTime.Now; entity.F46_Amount = model.AddQuantity; entity.F46_UpdateDate = DateTime.Now; entity.F46_UpdateCount = 0; _unitOfWork.SupMaterialStockRepository.Add(entity); } } _unitOfWork.Commit(); return(new ResponseResult(true)); }
public ResponseResult CreateOrUpdate(SubMaterialItem model) { if (model.IsCreate) { if (!string.IsNullOrEmpty(model.F15_SubMaterialCode)) { if (CheckUnique(model.F15_SubMaterialCode)) { return(new ResponseResult(false, Constants.Messages.Material_MSG004)); } } var entity = Mapper.Map <TM15_SubMaterial>(model); entity.F15_AddDate = DateTime.Now; entity.F15_UpdateCount = 0; entity.F15_EntrustedClass = "Norm".Equals(model.Bail, StringComparison.InvariantCultureIgnoreCase) ? Constants.Bailment.Normal.ToString("D") : Constants.Bailment.Bailment.ToString("D"); entity.F15_UpdateDate = DateTime.Now; _unitOfWork.SubMaterialRepository.Add(entity); //Add f46_SubMaterialCode var subMtrStk = new TX46_SupMtrStk(); subMtrStk.F46_SubMaterialCode = model.F15_SubMaterialCode; subMtrStk.F46_Comment = ""; subMtrStk.F46_StorageDate = DateTime.Now; subMtrStk.F46_Amount = 0.0; subMtrStk.F46_AddDate = DateTime.Now; subMtrStk.F46_UpdateDate = DateTime.Now; subMtrStk.F46_UpdateCount = 0; _unitOfWork.SupMaterialStockRepository.Add(subMtrStk); } else { var entity = _unitOfWork.SubMaterialRepository.GetAll().FirstOrDefault(i => i.F15_SubMaterialCode.Trim().Equals(model.F15_SubMaterialCode.Trim())); if (entity == null) { return(new ResponseResult(false, Constants.Messages.Material_MSG001)); } var addDate = entity.F15_AddDate; var count = entity.F15_UpdateCount; Mapper.Map(model, entity); entity.F15_EntrustedClass = "Norm".Equals(model.Bail, StringComparison.InvariantCultureIgnoreCase) ? Constants.Bailment.Normal.ToString("D") : Constants.Bailment.Bailment.ToString("D"); entity.F15_AddDate = addDate; entity.F15_UpdateDate = DateTime.Now; entity.F15_UpdateCount = count + 1; _unitOfWork.SubMaterialRepository.Update(entity); } _unitOfWork.Commit(); return(new ResponseResult(true)); }