示例#1
0
        public HttpResponseMessage Post(Colaborator colaborator)
        {
            if (colaborator == null)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Colaborador Inválido"));
            }

            var service = ColaboratorServiceFactory.Create();

            try
            {
                service.AddColaborator(colaborator);
            }
            catch (ApplicationValidationErrorsException exception)
            {
                var errors = new ModelStateDictionary();
                foreach (var error in exception.ValidationErrors)
                {
                    errors.AddModelError(error.Key, error.Value);
                }
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, errors));
            }

            return(Request.CreateResponse(HttpStatusCode.OK, colaborator));
        }
示例#2
0
        public void ColaboratorServiceFactoryCreateMethodShouldBeReturnAnInstanceOfColaboratorService()
        {
            var colaboratorService = ColaboratorServiceFactory.Create();

            Assert.IsNotNull(colaboratorService);
            Assert.IsInstanceOfType(colaboratorService, typeof(ColaboratorService));
        }
示例#3
0
        public HttpResponseMessage Put(Colaborator colaborator)
        {
            if (colaborator == null || colaborator.Id == 0)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Este colaborador não existe"));
            }

            var service = ColaboratorServiceFactory.Create();

            try
            {
                service.UpdateColaborator(colaborator);
            }
            catch (ApplicationValidationErrorsException exception)
            {
                var errors = new ModelStateDictionary();
                foreach (var validationError in exception.ValidationErrors)
                {
                    errors.AddModelError(validationError.Key, validationError.Value);
                }
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, errors));
            }


            return(Request.CreateResponse(HttpStatusCode.OK, colaborator));
        }
示例#4
0
        public IEnumerable <Colaborator> Get()
        {
            var service      = ColaboratorServiceFactory.Create();
            var colaborators = service.FindColaborators();

            return(colaborators.ToList().OrderByDescending(x => x.Id));
        }
示例#5
0
        public IEnumerable <Colaborator> Get(string filter)
        {
            var service = ColaboratorServiceFactory.Create();

            if (string.IsNullOrEmpty(filter))
            {
                return(service.FindColaborators());
            }
            return(service.FindColaborators(x => x.Name.Contains(filter) || x.Registry == filter));
        }
示例#6
0
        public HttpResponseMessage Get(int id)
        {
            var service     = ColaboratorServiceFactory.Create();
            var colaborator = service.FindColaboratorById(id);

            if (colaborator == null)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, new HttpError("Este colaborador não existe")));
            }

            return(Request.CreateResponse(HttpStatusCode.OK, colaborator));
        }
示例#7
0
        public void Delete(int id)
        {
            var service = ColaboratorServiceFactory.Create();

            service.RemoveColaborator(id);
        }