public JsonResult PersenceSupport_Update(Guid PersenceSupportID, short SupportType, string Problem, string PlanDate,
                                                 string PlanTimeFrom, string PlanTimeTo, string PlanNote, int RowVersion)
        {
            GeneralResponse response = new GeneralResponse();

            #region Access Check
            bool hasPermission = GetEmployee().IsGuaranteed("PersenceSupport_Update");
            if (!hasPermission)
            {
                response.ErrorMessages.Add("AccessDenied");
                return(Json(response, JsonRequestBehavior.AllowGet));
            }
            #endregion

            EditPersenceSupportRequest request = new EditPersenceSupportRequest();
            request.ID                 = PersenceSupportID;
            request.RowVersion         = RowVersion;
            request.ModifiedEmployeeID = GetEmployee().ID;
            request.SupportType        = SupportType;
            request.Problem            = Problem;
            request.PlanDate           = PlanDate;
            request.PlanTimeFrom       = PlanTimeFrom;
            request.PlanTimeTo         = PlanTimeTo;
            request.PlanNote           = PlanNote;

            response = this._persenceSupportService.EditPersenceSupport(request);

            return(Json(response, JsonRequestBehavior.AllowGet));
        }
Esempio n. 2
0
        public GeneralResponse EditPersenceSupport(EditPersenceSupportRequest request)
        {
            GeneralResponse response        = new GeneralResponse();
            PersenceSupport persenceSupport = new PersenceSupport();

            persenceSupport = _persenceSupportRepository.FindBy(request.ID);

            if (persenceSupport != null)
            {
                try
                {
                    // اگر تحویل شده بود قابل ویرایش نباشد
                    if (persenceSupport.Delivered)
                    {
                        response.ErrorMessages.Add("DeliveredAndCanNotBeEdited");
                        return(response);
                    }

                    persenceSupport.ModifiedDate     = PersianDateTime.Now;
                    persenceSupport.ModifiedEmployee = _employeeRepository.FindBy(request.ModifiedEmployeeID);
                    persenceSupport.PlanDate         = request.PlanDate;
                    persenceSupport.PlanNote         = request.PlanNote;
                    persenceSupport.PlanTimeFrom     = request.PlanTimeFrom;
                    persenceSupport.PlanTimeTo       = request.PlanTimeTo;
                    persenceSupport.Problem          = request.Problem;
                    persenceSupport.SupportType      = request.SupportType;
                    persenceSupport.Installer        = _employeeRepository.FindBy(request.InstallerID);

                    #region RowVersion Check

                    if (persenceSupport.RowVersion != request.RowVersion)
                    {
                        response.ErrorMessages.Add("کارشناس محترم، یک کاربر همزمان با شما در حال ویرایش این رکورد است. بنابراین اطلاعات شما ذخیره نمی شود.");
                        return(response);
                    }
                    else
                    {
                        persenceSupport.RowVersion += 1;
                        response.rowVersion         = persenceSupport.RowVersion;
                    }

                    #endregion

                    #region Validation

                    if (persenceSupport.GetBrokenRules().Count() > 0)
                    {
                        foreach (BusinessRule businessRule in persenceSupport.GetBrokenRules())
                        {
                            response.ErrorMessages.Add(businessRule.Rule);
                        }

                        return(response);
                    }

                    #endregion

                    _persenceSupportRepository.Save(persenceSupport);
                    _uow.Commit();
                }
                catch (Exception ex)
                {
                    response.ErrorMessages.Add(ex.Message);
                }
            }
            else
            {
                response.ErrorMessages.Add("NoItemToEditKey");
            }
            return(response);
        }