Exemple #1
0
        public GeneralResponse EditAgency(EditAgencyRequest request, Guid modifiedEmployeeID)
        {
            GeneralResponse response = new GeneralResponse();

            try
            {
                Agency agency = new Agency();
                agency = _agencyRepository.FindBy(request.ID);

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

                    agency.ModifiedEmployee = _employeeRepository.FindBy(modifiedEmployeeID);
                    if (request.AgencyName != null)
                    {
                        agency.AgencyName = request.AgencyName;
                    }
                    if (request.ManagerName != null)
                    {
                        agency.ManagerName = request.ManagerName;
                    }
                    if (request.Phone1 != null)
                    {
                        agency.Phone1 = request.Phone1;
                    }
                    if (request.Phone2 != null)
                    {
                        agency.Phone2 = request.Phone2;
                    }
                    if (request.Mobile != null)
                    {
                        agency.Mobile = request.Mobile;
                    }
                    if (request.Address != null)
                    {
                        agency.Address = request.Address;
                    }
                    if (request.Note != null)
                    {
                        agency.Note = request.Note;
                    }

                    agency.Discontinued = request.Discontinued;

                    #region RowVersion - Validation
                    if (agency.RowVersion != request.RowVersion)
                    {
                        response.ErrorMessages.Add("EditConcurrencyKey");
                        return(response);
                    }
                    else
                    {
                        agency.RowVersion += 1;
                    }

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

                        return(response);
                    }

                    #endregion

                    _agencyRepository.Save(agency);
                }
                else
                {
                    response.ErrorMessages.Add("NoItemToEditKey");
                }
                _uow.Commit();
            }
            catch (Exception ex)
            {
                response.ErrorMessages.Add(ex.Message);
                if (ex.InnerException != null)
                {
                    response.ErrorMessages.Add(ex.InnerException.Message);
                }
            }

            return(response);
        }