Exemple #1
0
        public IHttpActionResult Postrestaurante(restaurante restaurante)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.restaurante.Add(restaurante);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (restauranteExists(restaurante.id))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = restaurante.id }, restaurante));
        }
        public IHttpActionResult Putrestaurante(int id, restaurante restaurante)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemple #3
0
 public PedidoViewModel()
 {
     PedidoCabecera    = new pedido_cabecera();
     PedidoDetalleList = new List <pedido_detalle>();
     PedidoDetalle     = new pedido_detalle();
     Restaurante       = new restaurante();
 }
Exemple #4
0
        public ActionResult DeleteConfirmed(int id)
        {
            restaurante restaurante = db.restaurantes.Find(id);

            db.restaurantes.Remove(restaurante);
            db.SaveChanges();
            return(RedirectToAction("List"));
        }
Exemple #5
0
        public ActionResult DeleteConfirmed(int id)
        {
            restaurante restaurante = _context.restaurante.Find(id);

            _context.restaurante.Remove(restaurante);
            _context.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemple #6
0
 public ActionResult Edit([Bind(Include = "id,nombre,horario,principal,capacidad")] restaurante restaurante)
 {
     if (ModelState.IsValid)
     {
         db.Entry(restaurante).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index/" + restaurante.id));
     }
     return(View(restaurante));
 }
        public IHttpActionResult Getrestaurante(int id)
        {
            restaurante restaurante = db.restaurante.Find(id);

            if (restaurante == null)
            {
                return(NotFound());
            }

            return(Ok(restaurante));
        }
Exemple #8
0
 public ActionResult Edit([Bind(Include = "restaurante_id,empresa_id_fk,nombre,foto")] restaurante restaurante)
 {
     if (ModelState.IsValid)
     {
         _context.Entry(restaurante).State = EntityState.Modified;
         _context.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.empresa_id_fk = new SelectList(_context.empresa, "empresa_id", "nombre", restaurante.empresa_id_fk);
     return(View(restaurante));
 }
Exemple #9
0
        public ActionResult Create([Bind(Include = "id,nombre,horario,principal,capacidad")] restaurante restaurante)
        {
            if (ModelState.IsValid)
            {
                db.restaurantes.Add(restaurante);
                db.SaveChanges();
                return(RedirectToAction("List"));
            }

            return(View(restaurante));
        }
Exemple #10
0
 public IActionResult Post(restaurante data)
 {
     try
     {
         _restauranteService.Save(data);
         return(Ok());
     }
     catch (Exception ex)
     {
         return(StatusCode(500, ex.Message));
     }
 }
Exemple #11
0
 public IActionResult Put(int id, restaurante data)
 {
     try
     {
         _restauranteService.Update(id, data);
         return(Ok());
     }
     catch (Exception ex)
     {
         return(StatusCode(500, ex.Message));
     }
 }
        public IHttpActionResult Postrestaurante(restaurante restaurante)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.restaurante.Add(restaurante);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = restaurante.idRes }, restaurante));
        }
 public ActionResult Guardar(restaurante empresa)
 {
     ViewBag.Empresa = empresa.Listar();
     if (ModelState.IsValid)
     {
         empresa.guardar();
         return(Redirect("~/restaurante"));
     }
     else
     {
         return(View("~/Views/restaurante/Agregar.cshtml", empresa));
     }
 }
Exemple #14
0
        // GET: Admin/Restaurantes/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            restaurante restaurante = _context.restaurante.Find(id);

            if (restaurante == null)
            {
                return(HttpNotFound());
            }
            return(View(restaurante));
        }
Exemple #15
0
        // GET: restaurantes/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            restaurante restaurante = db.restaurantes.Find(id);

            if (restaurante == null)
            {
                return(HttpNotFound());
            }
            return(View(restaurante));
        }
        public IHttpActionResult Deleterestaurante(int id)
        {
            restaurante restaurante = db.restaurante.Find(id);

            if (restaurante == null)
            {
                return(NotFound());
            }

            db.restaurante.Remove(restaurante);
            db.SaveChanges();

            return(Ok(restaurante));
        }
Exemple #17
0
        // GET: Admin/Restaurantes/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            restaurante restaurante = _context.restaurante.Find(id);

            if (restaurante == null)
            {
                return(HttpNotFound());
            }
            ViewBag.empresa_id_fk = new SelectList(_context.empresa, "empresa_id", "nombre", restaurante.empresa_id_fk);
            return(View(restaurante));
        }
Exemple #18
0
        public void Update(int id, restaurante prato)
        {
            var oldRestaurante = _context.restaurante.Find(id);

            if (oldRestaurante == null)
            {
                throw new Exception("Restaurante não encontrato.");
            }

            var newRestaurante = prato;

            oldRestaurante.nome = newRestaurante.nome;
            _context.Entry(oldRestaurante).State = EntityState.Modified;
            _context.SaveChanges();
        }
Exemple #19
0
 public IActionResult Save([FromBody] restaurante restaurante)
 {
     try
     {
         if (ModelState.IsValid)
         {
             _svc.Add(restaurante);
             return(new CreatedAtRouteResult("Restaurante salvo com sucesso!", new { id = restaurante.id, url = "api/restaurante/" + restaurante.id }));
         }
         return(BadRequest(ModelState));
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
Exemple #20
0
 public IActionResult Update([FromBody] restaurante restaurante, int id)
 {
     try
     {
         if (restaurante.id != id)
         {
             return(BadRequest());
         }
         _svc.Update(restaurante);
         return(Ok("Atualizado com sucesso"));
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
Exemple #21
0
        public ActionResult DeleteRestaurant(Int32 RestaurantId)
        {
            try
            {
                restaurante rest = context.restaurante.Find(RestaurantId);
                rest.deleted_at = DateTime.Now;

                context.SaveChanges();
                PostMessage(MessageType.Success);
                return(RedirectToAction("ListRestaurant"));
            }
            catch (Exception ex)
            {
                PostMessage(MessageType.Error);
                return(RedirectToAction("ListRestaurant"));
            }
        }
        public static void Initializer(RestauranteContext context)
        {
            if (context.restaurantes.Any())
            {
                return;
            }

            var restaurantes = new restaurante[]
            {
                new restaurante
                {
                    id   = 1,
                    nome = "Primeiro Restaurante SA."
                }
            };
            var pratos = new prato[]
            {
                new prato
                {
                    id             = 1,
                    nome           = "Galinhada",
                    preco          = 10,
                    restaurante_id = 1
                },
                new prato
                {
                    id             = 2,
                    nome           = "Feijoada",
                    preco          = 20.20M,
                    restaurante_id = 1
                }
            };

            context.AddRange(restaurantes);
            context.AddRange(pratos);
            context.SaveChanges();
        }
Exemple #23
0
 public HttpResponseMessage Post([FromBody] restaurante res)
 {
     modelo.restaurante.Add(res);
     return(ToJson(modelo.SaveChanges()));
 }
Exemple #24
0
        public ActionResult EditRestaurant(EditRestaurantViewModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    model.CargarDatos(CargarDatosContext(), model.RestaurantId);
                    TryUpdateModel(model);
                    PostMessage(MessageType.Error, i18n.ValidationStrings.DatosIncorrectos);
                    return(View(model));
                }

                using (TransactionScope transaction = new TransactionScope())
                {
                    var restaurant         = new restaurante();
                    var categoryrestaurant = new restaurante_categoria();

                    if (model.RestaurantId.HasValue)
                    {
                        restaurant         = context.restaurante.First(x => x.id == model.RestaurantId);
                        categoryrestaurant = context.restaurante_categoria.First(x => x.restaurante_id == model.RestaurantId);
                    }
                    else
                    {
                        restaurant.nombre      = model.Nombre;
                        restaurant.descripcion = model.Descripcion;
                        restaurant.latitud     = model.Latitud;
                        restaurant.longitud    = model.Longitud;
                        restaurant.created_by  = Session.GetUsuarioId();
                        restaurant.updated_by  = Session.GetUsuarioId();
                        restaurant.created_at  = DateTime.Now;
                        restaurant.updated_at  = DateTime.Now;
                        restaurant.deleted_at  = null;
                        restaurant.distrito_id = model.DistritoId;
                        context.restaurante.Add(restaurant);

                        context.SaveChanges();

                        categoryrestaurant.restaurante_id = restaurant.id;
                        categoryrestaurant.categoria_id   = model.CategoriaId;
                        context.SaveChanges();

                        context.restaurante_categoria.Add(categoryrestaurant);
                    }

                    restaurant.nombre      = model.Nombre;
                    restaurant.descripcion = model.Descripcion;
                    restaurant.latitud     = model.Latitud;
                    restaurant.longitud    = model.Longitud;
                    restaurant.created_by  = Session.GetUsuarioId();
                    restaurant.updated_by  = Session.GetUsuarioId();
                    restaurant.created_at  = DateTime.Now;
                    restaurant.updated_at  = DateTime.Now;
                    restaurant.deleted_at  = null;
                    restaurant.distrito_id = model.DistritoId;
                    context.SaveChanges();

                    categoryrestaurant.restaurante_id = restaurant.id;
                    categoryrestaurant.categoria_id   = model.CategoriaId;
                    context.SaveChanges();

                    PostMessage(MessageType.Success, "Se registró el restaurante correctamente.");
                    transaction.Complete();

                    return(RedirectToAction("ListRestaurant"));
                }
            }
            catch (Exception ex)
            {
                InvalidarContext();
                PostMessage(MessageType.Error, "Ha ocurrido un error, por favor intentelo más tarde");
                model.CargarDatos(CargarDatosContext(), model.RestaurantId);
                TryUpdateModel(model);
                return(View(model));
            }
        }
 public restaurante Add(restaurante entity)
 {
     return(_dal.Add(entity));
 }
 public void Delete(restaurante entity)
 {
     _dal.Delete(entity);
 }
 public void Update(restaurante entity)
 {
     _dal.Update(entity);
 }
Exemple #28
0
 public API_RestauranteDetailPage(restaurante res)
 {
     InitializeComponent();
     resSelected         = res;
     this.BindingContext = res;
 }
Exemple #29
0
 public void Save(restaurante prato)
 {
     _context.restaurante.Add(prato);
     _context.SaveChanges();
 }
Exemple #30
0
 public HttpResponseMessage Put(long id, [FromBody] restaurante res)
 {
     modelo.Entry(res).State = EntityState.Modified;
     return(ToJson(modelo.SaveChanges()));
 }