Exemplo n.º 1
0
        public async Task Handle(CreatePersonCommand command, UnitOfWork uow)
        {
            IPersonRepository personRepository = PersonRepositoryFactory.Create(uow.Context);
            var person = new Person(command.Name, command.Email);

            personRepository.Add(person);
        }
Exemplo n.º 2
0
 public async Task <IList <Person> > Get()
 {
     using (var uow = UnitOfWork.Create())
     {
         IPersonRepository personRepository = PersonRepositoryFactory.Create(uow.Context);
         return(await personRepository.GetAsync(w => true));
     }
 }
Exemplo n.º 3
0
        public HttpResponseMessage Post(Person person)
        {
            var personRepository = PersonRepositoryFactory.PersonRepository();

            personBL = new PersonBL(personRepository);

            HttpResponseMessage response;

            // Initiate Validation.
            var validator            = new PersonValidator();
            ValidationResult results = validator.Validate(person, ruleSet: "Names");


            // Add error messages if any.
            ModelStateDictionary modelDictionary = new ModelStateDictionary();

            foreach (ValidationFailure result in results.Errors)
            {
                modelDictionary.AddModelError(result.PropertyName, result.ErrorMessage);
            }


            if (results.IsValid)
            {
                // Calls Business Logic to create.
                try
                {
                    personBL.CreatePerson(person);
                }
                catch (Exception ex)
                {
                    modelDictionary.AddModelError("Error", "Service Error");
                    return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, modelDictionary));
                }


                // Creates response
                response = Request.CreateResponse(HttpStatusCode.Created, person);
            }
            else
            {
                // Creates response
                response = Request.CreateErrorResponse(HttpStatusCode.BadRequest, modelDictionary);
            }

            return(response);
        }
 public PersonRepositoryTests()
     : base(PersonRepositoryFactory.Create(UnitOfWork.Create().Context))
 {
 }