Exemplo 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));
            }
        }
Exemplo n.º 2
0
        //
        // GET: /Hydranten/Default/

        public ActionResult Index()
        {
            using (HydrantenContext context = new HydrantenContext())
            {
                return(View(context.hydrantens.ToList()));
            }
        }
Exemplo n.º 3
0
        public IEnumerable <Hydrant> SearchHydranten(string search)
        {
            using (HydrantenContext context = new HydrantenContext())
            {
                PropertyInfo[] properties = typeof(Hydrant).GetProperties();
                foreach (Hydrant hydrant in context.hydrantens)
                {
                    foreach (PropertyInfo property in properties)
                    {
                        object value;
                        try
                        {
                            value = property.GetValue(hydrant, null);
                        }
                        catch (Exception ex)
                        {
                            //Well in some properties I can't search ... go on and hope that I find a matching one!
                            continue;
                        }
                        if (value != null && Convert.ToString(value).Contains(search))
                        {
                            yield return(hydrant);

                            break;
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
        //
        // GET: /Hydranten/Default/Details/5

        public ActionResult Details(int id)
        {
            using (HydrantenContext context = new HydrantenContext())
            {
                context.hydrant_ergebnis.Load();
                context.hydrant_lage.Load();
                return(View(context.hydrantens.FirstOrDefault(x => x.ID == id)));
            }
        }
Exemplo n.º 5
0
 public ActionResult GetImage(int id)
 {
     using (HydrantenContext context = new HydrantenContext())
     {
         Hydrant hydrant = context.hydrantens.FirstOrDefault(x => x.ID == id);
         if (hydrant == null || string.IsNullOrWhiteSpace(hydrant.ImagePath))
         {
             return(null);
         }
         else
         {
             string mapPath = Server.MapPath("~/upload/");
             return(File(Path.Combine(mapPath, hydrant.ImagePath), GetMimeType(hydrant.ImagePath)));
         }
     }
 }
Exemplo n.º 6
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());
            }
        }