Ejemplo n.º 1
0
        public ModifyTerritoryResponse ModifyTerritory(ModifyTerritoryRequest request)
        {
            ModifyTerritoryResponse response = new ModifyTerritoryResponse();

            Territory territory = _territoryRepository
                                  .FindBy(request.TerritoryID);

            territory.Id = request.TerritoryID;
            territory.TerritoryDescription = request.TerritoryDescription;
            territory.Employees            = request.Employees.ConvertToEmployees();
            territory.Region = request.Region.ConvertToRegion();


            if (territory.GetBrokenRules().Count() > 0)
            {
                response.Errors = territory.GetBrokenRules().ToList();
            }
            else
            {
                try {
                    _territoryRepository.Save(territory);
                    _uow.Commit();
                    response.Errors = new List <BusinessRule>();
                } catch (Exception ex)
                {
                    response.Errors = new List <BusinessRule>();
                    response.Errors.Add(new BusinessRule("DAL", "DAL_ERROR: " + ex.Message));
                }
            }


            return(response);
        }
Ejemplo n.º 2
0
        public CreateTerritoryResponse CreateTerritory(CreateTerritoryRequest request)
        {
            CreateTerritoryResponse response = new CreateTerritoryResponse();
            Territory territory = new Territory();

            territory.TerritoryDescription = request.TerritoryDescription;
            territory.Employees            = request.Employees.ConvertToEmployees();
            territory.Region = request.Region.ConvertToRegion();

            if (territory.GetBrokenRules().Count() > 0)
            {
                response.Errors = territory.GetBrokenRules().ToList();
            }
            else
            {
                try {
                    _territoryRepository.Add(territory);
                    _uow.Commit();
                    response.Errors = new List <BusinessRule>();
                } catch (Exception ex)
                {
                    List <BusinessRule> errors = new List <BusinessRule>();
                    do
                    {
                        errors.Add(new BusinessRule("DAL", "DAL_ERROR: " + ex.Message));
                        ex = ex.InnerException;
                    } while (ex != null);

                    response.Errors = errors;
                }
            }

            return(response);
        }