Ejemplo n.º 1
0
        public ActionResult Create(Hydrant model)
        {
            if (ModelState.IsValid)
            {
                if (model.UploadFile != null)
                {
                    string mapPath = Server.MapPath("~/upload/");
                    if (!Directory.Exists(mapPath))
                    {
                        Directory.CreateDirectory(mapPath);
                    }
                    model.UploadFile.SaveAs(Path.Combine(mapPath, model.UploadFile.FileName));
                    model.ImagePath = model.UploadFile.FileName;
                }
                try
                {
                    using (HydrantenContext context = new HydrantenContext())
                    {
                        context.hydrantens.AddOrUpdate(model);
                        context.SaveChanges();
                    }

                    return(RedirectToAction("Index"));
                }
                catch
                {
                    return(View(model));
                }
            }
            else
            {
                return(View(model));
            }
        }
Ejemplo n.º 2
0
        public ActionResult Delete(int id, Hydrant model)
        {
            try
            {
                using (HydrantenContext context = new HydrantenContext())
                {
                    context.hydrantens.Remove(context.hydrantens.First(x => x.ID == id));
                    context.SaveChanges();
                }

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }