Esempio n. 1
0
        public async Task <ActionResult> InsertAsync([FromBody] AddBarbequeModel model)
        {
            try {
                if (string.IsNullOrEmpty(model.Description))
                {
                    throw new ArgumentNullException(nameof(model.Description));
                }

                if (model.EventDateTime == null)
                {
                    throw new ArgumentNullException(nameof(model.EventDateTime));
                }

                return(Json(await _barbequeService.AddAsync(model)));
            }
            catch (Exception ex)
            {
                if (ex is ArgumentNullException || ex is ArgumentException)
                {
                    return(BadRequest(ex));
                }

                if (ex is ApplicationException)
                {
                    return(UnprocessableEntity(ex));
                }

                return(StatusCode(500, new Exception("Ops, tivemos um problema")));
            }
        }
Esempio n. 2
0
        public async Task <Barbeque> UpdateAsync(int id, AddBarbequeModel updatedBbq)
        {
            Barbeque bbq = new Barbeque(updatedBbq.Description, updatedBbq.EventDateTime);

            bbq.Id = id;
            return(await _barbequeRepository.Update(bbq));
        }
Esempio n. 3
0
        public async Task <ActionResult> UpdateAsync(int id, [FromBody] AddBarbequeModel data)
        {
            try
            {
                if (data.EventDateTime == null)
                {
                    throw new ArgumentNullException(nameof(data.EventDateTime));
                }

                if (!(id >= 1))
                {
                    throw new ArgumentException(nameof(id));
                }

                return(Json(await _barbequeService.UpdateAsync(id, data)));
            }
            catch (Exception ex)
            {
                if (ex is ArgumentNullException || ex is ArgumentException)
                {
                    return(BadRequest(ex));
                }

                if (ex is ApplicationException)
                {
                    return(UnprocessableEntity(ex));
                }

                return(StatusCode(500, new Exception("Ops, tivemos um problema")));
            }
        }
Esempio n. 4
0
        public async Task <Barbeque> AddAsync(AddBarbequeModel insertedBbq)
        {
            Barbeque bbq = new Barbeque(insertedBbq.Description, insertedBbq.EventDateTime);

            return(await _barbequeRepository.AddAsync(bbq));
        }