public ActionResult Edit(Sucursale sucursale)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    try
                    {
                        dbCtx.Entry(sucursale).State = System.Data.Entity.EntityState.Modified;
                        dbCtx.SaveChanges();
                    }
                    catch (DbEntityValidationException e)
                    {
                        foreach (var eve in e.EntityValidationErrors)
                        {
                            Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                              eve.Entry.Entity.GetType().Name, eve.Entry.State);
                            foreach (var ve in eve.ValidationErrors)
                            {
                                Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage);
                            }
                        }
                        throw;
                    }
                }

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
        public ActionResult Delete(int id)
        {
            try
            {
                try
                {
                    Sucursale sucursale = dbCtx.Sucursales.Find(id);
                    dbCtx.Sucursales.Remove(sucursale);
                    dbCtx.SaveChanges();
                }
                catch (DbEntityValidationException e)
                {
                    foreach (var eve in e.EntityValidationErrors)
                    {
                        Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                          eve.Entry.Entity.GetType().Name, eve.Entry.State);
                        foreach (var ve in eve.ValidationErrors)
                        {
                            Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage);
                        }
                    }
                    throw;
                }

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
        public ActionResult DeleteConfirmed(int id)
        {
            Sucursale sucursale = db.Sucursales.Find(id);

            db.Sucursales.Remove(sucursale);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "ID_sucursal,nombre,direccion,canton,distrito,provincia,telefono,correo")] Sucursale sucursale)
 {
     if (ModelState.IsValid)
     {
         db.Entry(sucursale).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(sucursale));
 }
        // GET: Sucursale/Edit/5
        public ActionResult Edit(int id)
        {
            Sucursale sucursale = dbCtx.Sucursales.Find(id);

            if (sucursale == null)
            {
                return(HttpNotFound());
            }
            return(View(sucursale));
        }
        public ActionResult Create([Bind(Include = "ID_sucursal,nombre,direccion,canton,distrito,provincia,telefono,correo")] Sucursale sucursale)
        {
            if (ModelState.IsValid)
            {
                db.Sucursales.Add(sucursale);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(sucursale));
        }
        // GET: Sucursales/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Sucursale sucursale = db.Sucursales.Find(id);

            if (sucursale == null)
            {
                return(HttpNotFound());
            }
            return(View(sucursale));
        }
예제 #8
0
        public async Task <HttpResponseMessage> Guardar(HttpRequestMessage request, Sucursale data)
        {
            return(await CreateHttpResponseAsync(request, async() =>
            {
                HttpResponseMessage response = null;
                string message = String.Empty;
                try
                {
                    var result = _sucursalService.InsertUpdateSucursal(data, out message);
                    if (result)
                    {
                        response = request.CreateResponse(HttpStatusCode.OK);
                    }
                    else
                    {
                        response = request.CreateResponse(HttpStatusCode.BadRequest,
                                                          new
                        {
                            error = "ERROR",
                            message = message
                        });
                    }
                }
                catch (Exception ex)
                {
                    response = request.CreateResponse(HttpStatusCode.BadRequest,
                                                      new
                    {
                        error = "ERROR",
                        message = ex.Message
                    });
                }

                return await Task.FromResult(response);
            }));
        }
        public ActionResult Nuevo(SucursaleViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    using (EurekaLibreriaDBEntities db = new EurekaLibreriaDBEntities())
                    {
                        var xSucursale = new Sucursale();
                        xSucursale.Nombre    = model.Nombre;
                        xSucursale.Direccion = model.Direccion;

                        db.Sucursales.Add(xSucursale);
                        db.SaveChanges();
                    }
                    return(Redirect("~/Sucursale/"));
                }
                return(View(model));
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }