Пример #1
0
 public static SettingRegRespObj UpdateWorkflowOrderItem(EditWorkFlowOrderItemObj regObj)
 {
     return(new WorkflowOrderItemRepository().UpdateWorkflowOrderItem(regObj));
 }
Пример #2
0
        public SettingRegRespObj UpdateWorkflowOrderItem(EditWorkFlowOrderItemObj regObj)
        {
            var response = new SettingRegRespObj
            {
                Status = new APIResponseStatus
                {
                    IsSuccessful = false,
                    Message      = new APIResponseMessage()
                }
            };

            try
            {
                if (regObj.Equals(null))
                {
                    response.Status.Message.FriendlyMessage  = "Error Occurred! Unable to proceed with your request";
                    response.Status.Message.TechnicalMessage = "Registration Object is empty / invalid";
                    return(response);
                }

                if (!EntityValidatorHelper.Validate(regObj, out var valResults))
                {
                    var errorDetail = new StringBuilder();
                    if (!valResults.IsNullOrEmpty())
                    {
                        errorDetail.AppendLine("Following error occurred:");
                        valResults.ForEachx(m => errorDetail.AppendLine(m.ErrorMessage));
                    }

                    else
                    {
                        errorDetail.AppendLine(
                            "Validation error occurred! Please check all supplied parameters and try again");
                    }
                    response.Status.Message.FriendlyMessage  = errorDetail.ToString();
                    response.Status.Message.TechnicalMessage = errorDetail.ToString();
                    response.Status.IsSuccessful             = false;
                    return(response);
                }

                if (!HelperMethods.IsUserValid(regObj.AdminUserId, regObj.SysPathCode,
                                               HelperMethods.getSeniorAccountant(), ref response.Status.Message))
                {
                    return(response);
                }

                var thisWorkflowOrderItem = getWorkflowOrderItemInfo(regObj.WorkflowOrderItemId);

                if (thisWorkflowOrderItem == null)
                {
                    response.Status.Message.FriendlyMessage =
                        "No WorkflowOrderItem Information found for the specified WorkflowOrderItem Id";
                    response.Status.Message.TechnicalMessage = "No WorkflowOrderItem Information found!";
                    return(response);
                }

                if (IsWorkflowOrderItemDuplicate(regObj.Name, regObj.WorkflowOrderId, regObj.Order, 1, ref response))
                {
                    return(response);
                }

                thisWorkflowOrderItem.Name            = regObj.Name;
                thisWorkflowOrderItem.WorkflowOrderId = regObj.WorkflowOrderId;
                thisWorkflowOrderItem.Order           = regObj.Order;
                thisWorkflowOrderItem.Status          = (ItemStatus)regObj.Status;

                var added = _repository.Update(thisWorkflowOrderItem);
                _uoWork.SaveChanges();

                if (added.WorkflowOrderItemId < 1)
                {
                    response.Status.Message.FriendlyMessage =
                        "Error Occurred! Unable to complete your request. Please try again later";
                    response.Status.Message.TechnicalMessage = "Unable to save to database";
                    return(response);
                }
                resetCache();
                response.Status.IsSuccessful = true;
                response.SettingId           = added.WorkflowOrderItemId;
            }
            catch (DbEntityValidationException ex)
            {
                ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                response.Status.Message.FriendlyMessage  = "Error Occurred! Please try again later";
                response.Status.Message.TechnicalMessage = "Error: " + ex.GetBaseException().Message;
                response.Status.IsSuccessful             = false;
                return(response);
            }
            catch (Exception ex)
            {
                ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                response.Status.Message.FriendlyMessage  = "Error Occurred! Please try again later";
                response.Status.Message.TechnicalMessage = "Error: " + ex.GetBaseException().Message;
                response.Status.IsSuccessful             = false;
                return(response);
            }
            return(response);
        }