public ActionResult GoToFilePicker(PosterModel model)
 {
     if (model.Type == PosterCandidateType.Application && db.EventApplications.Find(model.Id) != null) return View("AddPoster", model);
     else if (model.Type == PosterCandidateType.Event && db.Events.Find(model.Id) != null) return View("AddPoster", model);
     else return new HttpNotFoundResult();
 }
        public ActionResult AddPoster(PosterModel model, HttpPostedFileBase fileUpload)
        {
            if (model.Type == PosterCandidateType.Application)
            {
                EventApplication application = db.EventApplications.Find(model.Id);
                if (application == null)
                {
                    return new HttpNotFoundResult();
                }
                else
                {
                    var path = "";
                    if (Request.Files.Count > 0)
                    {
                        var file = Request.Files[0];

                        if (file != null && file.ContentLength > 0)
                        {
                            var fileName = Path.GetFileName(file.FileName);
                            path = Path.Combine(Server.MapPath("~/Posters/"), fileName);
                            file.SaveAs(path);
                            path = "/Posters/" + fileName;
                        }
                    }
                    db.EventApplications.Remove(application);
                    Event e = db.Events.Add(new Event()
                    {
                        Name = application.Name,
                        CreatorEmail = application.CreatorEmail,
                        CreatorName = application.CreatorName,
                        CreatorPhone = application.CreatorPhone,
                        Description = application.Description,
                        From = application.From,
                        Till = application.Till,
                        PosterPath = path
                    });
                    db.SaveChanges();
                }
            }
            else
            {
                var entry = db.Events.Find(model.Id);
                var path = "";
                if (Request.Files.Count > 0)
                {
                    var file = Request.Files[0];

                    if (file != null && file.ContentLength > 0)
                    {
                        var fileName = Path.GetFileName(file.FileName);
                        path = Path.Combine(Server.MapPath("~/Posters/"), fileName);
                        file.SaveAs(path);
                        path = "/Posters/" + fileName;
                    }
                }
                entry.PosterPath = path;
                db.Entry(entry).State = EntityState.Modified;
                db.SaveChanges();
            }
            return RedirectToAction("Index");
        }