예제 #1
0
 public ActionResult <IEnumerable <Model.Restaurante> > Post([FromBody] Model.Restaurante restaurante)
 {
     try
     {
         if (restaurante.id == 0)
         {
             context.Restaurantes.Add(restaurante);
             context.SaveChanges();
             return(context.Restaurantes);
         }
         var pratosLista = context.Pratos.Where(r => r.restauranteId == restaurante.id);
         foreach (var prato in pratosLista)
         {
             prato.restauranteNome      = restaurante.nome;
             context.Entry(prato).State = EntityState.Modified;
             //context.SaveChanges();
         }
         context.Entry(restaurante).State = EntityState.Modified;
         context.SaveChanges();
         return(context.Restaurantes);
     }
     catch (Exception e)
     {
         return(StatusCode(500));
     }
 }
        public IHttpActionResult PutRestaurante(int id, Restaurante restaurante)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != restaurante.Id)
            {
                return(BadRequest());
            }

            db.Entry(restaurante).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RestauranteExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
예제 #3
0
        public async Task <IActionResult> PutCliente(string id, Cliente cliente)
        {
            if (id != cliente.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
예제 #4
0
        public async Task <IActionResult> PutMesa(int id, Mesa mesa)
        {
            if (id != mesa.MesaId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
예제 #5
0
        public async Task <IActionResult> PutPedido(int id, Pedido pedido)
        {
            if (id != pedido.PedidoId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
예제 #6
0
 public ActionResult Edit([Bind(Include = "RestauranteID,Descricao")] Restaurante restaurante)
 {
     if (ModelState.IsValid)
     {
         db.Entry(restaurante).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(restaurante));
 }
예제 #7
0
        public async Task <ActionResult> Put(int id, Producto producto)
        {
            if (id == producto.Id)
            {
                _context.Entry(producto).State = EntityState.Modified;
                await _context.SaveChangesAsync();

                return(NoContent());
            }
            return(BadRequest());
        }
예제 #8
0
        public async Task <ActionResult> Put(int id, DetalleOrden detalle)
        {
            if (id == detalle.Id)
            {
                _context.Entry(detalle).State = EntityState.Modified;
                await _context.SaveChangesAsync();

                return(NoContent());
            }
            return(BadRequest());
        }
예제 #9
0
        public ActionResult Edit([Bind(Include = "PratoID,Descricao,RestauranteID,Preco")] Prato prato)
        {
            if (ModelState.IsValid)
            {
                //prato.Preco.ToString().f

                db.Entry(prato).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.RestauranteID = new SelectList(db.Restaurantes, "RestauranteID", "Descricao", prato.RestauranteID);
            return(View(prato));
        }
예제 #10
0
        public async Task <ActionResult <Restaurant> > EditRestaurant(long id, [FromBody] Restaurant restaurant)
        {
            if (id != restaurant.Id)
            {
                BadRequest();
            }

            //restaurantItem = restaurant;

            _context.Entry(restaurant).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetRestaurant), new { id = restaurant.Id }, restaurant));
        }
예제 #11
0
        public async Task <ActionResult <Plate> > EditPlate(long id, [FromBody] Plate plate)
        {
            if (id != plate.Id)
            {
                BadRequest();
            }

            //restaurantItem = restaurant;

            _context.Entry(plate).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetPlate), new { id = plate.Id }, plate));
        }
예제 #12
0
        public async Task <T> Update(T item)
        {
            var resultado = await dataset.SingleOrDefaultAsync(i => i.Id.Equals(item.Id));

            try
            {
                if (resultado == null)
                {
                    throw new Exception("O item informado não existe");
                }
                _context.Entry(resultado).CurrentValues.SetValues(item);
                await _context.SaveChangesAsync();

                return(resultado);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #13
0
        public ActionResult <IEnumerable <Model.Prato> > Post([FromBody] Model.Prato prato)
        {
            try
            {
                var restaurante = context.Restaurantes.Find(prato.restauranteId);
                prato.restauranteNome = restaurante.nome;

                if (prato.id == 0)
                {
                    context.Pratos.Add(prato);
                    context.SaveChanges();
                    return(context.Pratos);
                }
                context.Entry(prato).State = EntityState.Modified;
                context.SaveChanges();
                return(context.Pratos);
            }
            catch
            {
                return(StatusCode(500));
            }
        }
예제 #14
0
        public async Task <ResultHelper <Orden> > Update(Orden orden, int id)
        {
            var resultado = new ResultHelper <Orden>();

            try
            {
                if (id == orden.Id)
                {
                    _context.Entry(orden).State = EntityState.Modified;
                    await _context.SaveChangesAsync();

                    resultado.Value = orden;
                }
                else
                {
                    resultado.AddError("El id no coincide con el id de la orden");
                }
            }
            catch (Exception e)
            {
                resultado.AddError(e.Message);
            }
            return(resultado);
        }
 public void Salvar(Restaurante entity)
 {
     db.Entry(entity).State = entity.RestauranteID == 0 ?
                              EntityState.Added : System.Data.Entity.EntityState.Modified;
     db.SaveChanges();
 }
예제 #16
0
 public virtual void Alterar(T entidade)
 {
     _context.Entry(entidade).State = System.Data.Entity.EntityState.Modified;
 }
예제 #17
0
 public void Salvar(Prato entity)
 {
     db.Entry(entity).State = entity.PratoID == 0 ?
                              EntityState.Added : EntityState.Modified;
     db.SaveChanges();
 }