Пример #1
0
        public Response Delete(int id)
        {
            Response response = new Response();

            if (id <= 0)
            {
                response.Erros.Add("ID do filme não foi informado.");
                return(response);
            }

            using (LocadoraDBContext db = new LocadoraDBContext())
            {
                try
                {
                    db.Entry(new Filme()
                    {
                        ID = id
                    }).State = System.Data.Entity.EntityState.Deleted;
                    db.SaveChanges();
                    response.Sucesso = true;
                    return(response);
                }
                catch (Exception ex)
                {
                    response.Erros.Add("Erro ao deletar um filme. Contate o admin!");
                    File.WriteAllText("log.txt", ex.Message);
                    return(response);
                }
            }
        }
Пример #2
0
        public async Task <IActionResult> PutFilmes(int id, Filmes filmes)
        {
            if (id != filmes.Id)
            {
                return(BadRequest());
            }

            _context.Entry(filmes).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!FilmesExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #3
0
        public Response Update(Filme item)
        {
            Response response = Validate(item);

            if (response.HasErrors())
            {
                response.Sucesso = false;
                return(response);
            }

            using (LocadoraDBContext db = new LocadoraDBContext())
            {
                try
                {
                    db.Entry(item).State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();
                    response.Sucesso = true;
                    return(response);
                }
                catch (Exception ex)
                {
                    response.Erros.Add("Erro ao atualizar um filme. Contate o admin!");
                    File.WriteAllText("log.txt", ex.Message);
                    return(response);
                }
            }
        }
Пример #4
0
        public async Task <IActionResult> PutUsuarios(int id, Usuarios usuarios)
        {
            //if (id != usuarios.IdUsuario)
            //{
            //    return BadRequest();
            //}

            usuarios.IdUsuario = id;

            _context.Entry(usuarios).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UsuariosExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }