Example #1
0
        /// <summary>
        /// POST: Inclui um DDD
        /// </summary>
        /// <param name="obj">Objeto com os dados do DDD à ser inserido</param>
        /// <returns></returns>
        public HttpResponseMessage Post(DDDViewModel obj)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _dddAppService.Incluir(obj);

                    HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, obj);
                    response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = obj.DDDId }));
                    return(response);
                }
                else
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
                }
            }
            catch (Exception)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
        }
Example #2
0
        /// <summary>
        /// PUT: Altera um DDD
        /// </summary>
        /// <param name="id">Identificador do DDD</param>
        /// <param name="obj">Todos os outros dados deste DDD</param>
        /// <returns></returns>
        public HttpResponseMessage Put(int id, DDDViewModel obj)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }

            if (id != obj.DDDId)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }

            try
            {
                _dddAppService.Alterar(obj);
            }
            catch (DbUpdateConcurrencyException ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex));
            }

            return(Request.CreateResponse(HttpStatusCode.OK));
        }
Example #3
0
 public void Alterar(DDDViewModel objViewModel)
 {
     _dddService.Alterar(Mapper.Map <DDD>(objViewModel));
 }
Example #4
0
        public void Incluir(DDDViewModel objViewModel)
        {
            var usu = Mapper.Map <DDD>(objViewModel);

            _dddService.Incluir(usu);
        }
Example #5
0
 public IEnumerable <DDDViewModel> Filtros(DDDViewModel objViewModel)
 {
     return(Mapper.Map <IEnumerable <DDDViewModel> >(_dddService.Filtros(Mapper.Map <DDD>(objViewModel))));
 }