public JsonResult SaveAdjustment(int scrimRollId, int actionTypeId, double adjustment, int uomId, string adjustmentReason) { TPO.Web.Core.ResponseMessage responseMessage; try { var model = new ScrimActionModel(); { model.ActionDate = DateTime.Now; model.PlantId = CurrentPlantId; model.ScrimRollID = scrimRollId; var uomModel = GetUomModel(uomId); var uomTypeModel = GetUomTypeModel(uomModel.TypeID); var scrimActionTypeModel = GetScrimActionTypeModel(actionTypeId); var scrimRollModel = GetScrimRollModel(scrimRollId); scrimRollModel.IsLoaded = true; model.StartLength = (double)scrimRollModel.Length; model.StartWeight = (double)scrimRollModel.Weight; var uoMConversionService = new UoMConversionService(); string adjustmentReasonText; if (uomTypeModel.Code == "L") { model.ActionLength = adjustment; decimal adjustmentLength = uoMConversionService.ConvertUoM(uomId, (decimal)adjustment, scrimRollModel.LengthUoMID); if (scrimActionTypeModel.Code == "SA") { scrimRollModel.LengthUsed -= adjustmentLength; scrimRollModel.Length += adjustmentLength; adjustmentReasonText = "(Adjusted length by " + adjustment + " " + uomModel.Code + ")"; } else { scrimRollModel.Length = adjustmentLength; scrimRollModel.LengthUsed = scrimRollModel.ReceivedLength - scrimRollModel.Length; adjustmentReasonText = "(Set length to " + adjustment + " " + uomModel.Code + ")"; } } else { model.ActionWeight = adjustment; decimal adjustmentWeight = uoMConversionService.ConvertUoM(uomId, (decimal)adjustment, scrimRollModel.WeightUoMID); if (scrimActionTypeModel.Code == "SA") { scrimRollModel.WeightUsed -= adjustmentWeight; scrimRollModel.Weight += adjustmentWeight; adjustmentReasonText = "(Adjusted weight by " + adjustment + " " + uomModel.Code + ")"; } else { scrimRollModel.Weight = adjustmentWeight; scrimRollModel.WeightUsed = scrimRollModel.ReceivedWeight - scrimRollModel.Weight; adjustmentReasonText = "(Set weight to " + adjustment + " " + uomModel.Code + ")"; } } if (adjustmentReason == null) { adjustmentReason = string.Empty; } else { adjustmentReason += " "; } model.DateEntered = DateTime.Now; model.EndLength = (double)scrimRollModel.Length; model.EndWeight = (double)scrimRollModel.Weight; model.EnteredBy = CurrentUser; model.LastModified = DateTime.Now; model.ModifiedBy = CurrentUser; model.RollID = null; model.TypeID = actionTypeId; model.UserID = GetUserModel(CurrentUser).Id; model.ActionReasonText = adjustmentReason + adjustmentReasonText; using (var scrimRollService = new ScrimRollService()) { var scrimActionDto = new ScrimActionDto(); Mapper.Map(model, scrimActionDto); var scrimRollDto = new ScrimRollDto(); Mapper.Map(scrimRollModel, scrimRollDto); scrimRollService.Update(scrimRollDto, scrimActionDto); SetResponseMesssage(ActionTypeMessage.SuccessfulSave); } } responseMessage = SetResponseMesssage(ActionTypeMessage.SuccessfulSave); } catch (Exception exc) { responseMessage = SetResponseMesssage(ActionTypeMessage.FailedSave, exc.Message); } return(Json(responseMessage, JsonRequestBehavior.AllowGet)); }
public JsonResult ScrimRollAjaxCreate(string id) { TPO.Web.Core.ResponseMessage responseMessage; try { ScrimRollService srsrv = new ScrimRollService(); ScrimRollModel model = JsonConvert.DeserializeObject <ScrimRollModel>(id); if (model != null) { var x = srsrv.GetAll().Where(q => q.Code == model.Code).ToList(); if (!x.Any()) { ScrimRollDto dto = new ScrimRollDto(); using (ScrimRollService service = new ScrimRollService()) { Mapper.Map(model, dto); dto.WovenDate = null; dto.PlantID = CurrentPlantId; dto.LastModified = DateTime.Now; dto.ModifiedBy = CurrentUser; if (model.Id > 0) { service.Update(dto); } else { dto.DateEntered = dto.LastModified; dto.EnteredBy = CurrentUser; service.Add(dto); } } } else { ScrimRollDto dto = new ScrimRollDto(); using (ScrimRollService service = new ScrimRollService()) { Mapper.Map(model, dto); dto.WovenDate = null; dto.PlantID = CurrentPlantId; dto.LastModified = DateTime.Now; dto.ModifiedBy = CurrentUser; dto.DateEntered = DateTime.Now; dto.EnteredBy = CurrentUser; service.Update(dto); } } } responseMessage = SetResponseMesssage(ActionTypeMessage.SuccessfulSave); } catch (Exception exc) { responseMessage = SetResponseMesssage(ActionTypeMessage.FailedSave, exc.Message); } return(Json(responseMessage, JsonRequestBehavior.AllowGet)); }