Ejemplo n.º 1
0
        public GeneralResponse EditProvince(EditProvinceRequest request)
        {
            GeneralResponse response = new GeneralResponse();
            Province        province = new Province();

            province = _provinceRepository.FindBy(request.ID);

            if (province != null)
            {
                try
                {
                    province.ModifiedDate = PersianDateTime.Now;

                    province.ModifiedEmployee = _employeeRepository.FindBy(request.ModifiedEmployeeID);

                    if (request.ProvinceName != null)
                    {
                        province.ProvinceName = request.ProvinceName;
                    }

                    if (province.RowVersion != request.RowVersion)
                    {
                        response.ErrorMessages.Add("EditConcurrencyKey");
                        return(response);
                    }
                    else
                    {
                        province.RowVersion += 1;
                    }

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

                        return(response);
                    }

                    _provinceRepository.Save(province);
                    _uow.Commit();

                    ////response.success = true;
                }
                catch (Exception ex)
                {
                    response.ErrorMessages.Add(ex.Message);
                    if (ex.InnerException != null)
                    {
                        response.ErrorMessages.Add(ex.InnerException.Message);
                    }
                }
            }
            else
            {
                response.ErrorMessages.Add("NoItemToEditKey");
            }
            return(response);
        }