Exemplo 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);
        }
Exemplo n.º 2
0
        public GeneralResponse AddProvince(AddProvinceRequest request)
        {
            GeneralResponse response = new GeneralResponse();

            try
            {
                Province province = new Province();
                province.ID             = Guid.NewGuid();
                province.CreateDate     = PersianDateTime.Now;
                province.CreateEmployee = _employeeRepository.FindBy(request.EmployeeId);
                province.ProvinceName   = request.ProvinceName;
                province.RowVersion     = 1;
                //Validation
                if (province.GetBrokenRules().Count() > 0)
                {
                    foreach (BusinessRule businessRule in province.GetBrokenRules())
                    {
                        response.ErrorMessages.Add(businessRule.Rule);
                    }
                    return(response);
                }
                _provinceRepository.Add(province);
                _uow.Commit();
            }
            catch (Exception ex)
            {
                response.ErrorMessages.Add(ex.Message);
                if (ex.InnerException != null)
                {
                    response.ErrorMessages.Add(ex.InnerException.Message);
                }
            }
            return(response);
        }