Ejemplo n.º 1
0
        public IHttpActionResult PostConsume(ConsumeViewModel consume)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }



            try
            {
                _consumeRepository.Add(consume.ToModel());
            }
            catch (DbUpdateException)
            {
                if (ConsumeExist(consume.Id))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = consume.Id }, consume));
        }
Ejemplo n.º 2
0
        public async Task <IHttpActionResult> PutConsume(Guid id, ConsumeViewModel consume)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != consume.Id)
            {
                return(BadRequest());
            }
            consume.Id = id;
            try
            {
                await _consumeRepository.EditAsync(consume.ToModel());
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ConsumeExist(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }