コード例 #1
0
        public ActionResult Application()
        {
            //   string LogPath = Server.MapPath(@"~\Log\");
            //   Notify.NotifyException(null , null, LogPath);


            ApplicationSessionStore store       = new ApplicationSessionStore(HttpContext.Session);
            Application             application = store.GetApplication();

            return(View(application));
        }
コード例 #2
0
        public ActionResult EditSupportingWork(int Id, Work work, IEnumerable <HttpPostedFileBase> fileUpload)
        {
            work = ViewHelpers.AddUploadToWork(work, fileUpload.First(), Server.MapPath("~/Uploads"));

            if (ModelState.IsValid)
            {
                ApplicationSessionStore store       = new ApplicationSessionStore(HttpContext.Session);
                Application             application = store.GetApplication();
                application.SupportingWorks[Id] = ViewHelpers.MergeFormPostWithExisting(application.SupportingWorks[Id], work);
                store.saveApplication(application);
                return(RedirectToAction("Application"));
            }
            else
            {
                return(View(work));
            }
        }
コード例 #3
0
        public ActionResult AddSupportingWork(Work work, IEnumerable <HttpPostedFileBase> fileUpload)
        {
            if (fileUpload.First() == null)
            {
                ModelState.AddModelError("Image", "An image is required for each supporting work");
            }

            work = ViewHelpers.AddUploadToWork(work, fileUpload.First(), Server.MapPath("~/Uploads"));

            if (ModelState.IsValid)
            {
                ApplicationSessionStore store       = new ApplicationSessionStore(HttpContext.Session);
                Application             application = store.GetApplication();
                application.SupportingWorks.Add(work);
                store.saveApplication(application);
                return(RedirectToAction("Application"));
            }
            else
            {
                return(View(work));
            }
        }
コード例 #4
0
        public ActionResult Application(Application postedApplication, IEnumerable <HttpPostedFileBase> fileUpload)
        {
            Application viewApplication = null;

            try
            {
                // Every time we post we need to save in case there was changes to the fields, even if the fields are invalid
                // We check for invalid fields at final submittal.
                ApplicationSessionStore store       = new ApplicationSessionStore(HttpContext.Session);
                Application             application = ViewHelpers.MergeFormPostWithExisting(store.GetApplication(), postedApplication);

                application.Work = ViewHelpers.AddUploadToWork(application.Work, fileUpload.First(), Server.MapPath("~/Uploads"));
                store.saveApplication(application);

                // Add/Edit/Delete Supporting Work
                if (Request.Form["AddSupportingWork"] != null)
                {
                    return(RedirectToAction("AddSupportingWork"));
                }

                var delKey = ViewHelpers.StartsWithIndex("DeleteSupportingWork", Request.Form.AllKeys);
                if (delKey != null)
                {
                    application.SupportingWorks.RemoveAt((int)delKey);
                    return(RedirectToAction("Application"));
                }

                var editKey = ViewHelpers.StartsWithIndex("EditSupportingWork", Request.Form.AllKeys);
                if (editKey != null)
                {
                    return(RedirectToAction("EditSupportingWork", new { id = (int)editKey }));
                }

                // Cancel submission
                if (Request.Form["CancelSubmission"] != null)
                {
                    store.deleteApplication();
                    return(RedirectToAction("Index"));
                }

                // Check that image has been added, or will be by this submit
                if (fileUpload.First() == null && application.Work.Image == null)
                {
                    ModelState.AddModelError("Work.Image", "An image is required for the nominated work");
                }

                // Save to db if valid, return with validation errors if not
                if (ModelState.IsValid)
                {
                    // Get the dbcontext container
                    var container = new ArtPrizeSubmissions.Models.Data.ApplicationsContainer();

                    // Make a repository, passing it the dbcontext container
                    Repository repo = new Repository((IApplicationsContainer)container);

                    // Get the application that was in the Session
                    //Application viewApplication = store.GetApplication();
                    viewApplication = store.GetApplication();

                    // Add the application to the repository, return a POCO view model application to use later
                    var app = repo.addApplication(viewApplication);

                    // Save changes
                    container.SaveChanges();

                    // app still points to the saved object, but the Id is now the one in the database
                    string recieptRef = String.Format("CHAP-12{0}", app.Id);

                    // Remove the application from the Session
                    store.deleteApplication();

                    // Show the Thank You/RecieptRef screen

                    string LogPath = Server.MapPath(@"~\Log\");
                    Notify.NotifyNewArtSubmission(viewApplication, LogPath);


                    return(RedirectToAction("ThankYou", new { Id = recieptRef }));
                }
                else
                {
                    return(View(application));
                }
            }
            catch (Exception e)
            {
                //TODO - EMAIL WITH AS MUCH DATA AS CAN GET
                string LogErrPath = Server.MapPath(@"~\Log\");
                Notify.NotifyException(e, viewApplication, LogErrPath);

                throw e;

                // ErrorHandler.Notify(e, viewApplication);
            }
        }
コード例 #5
0
        public ActionResult EditSupportingWork(int Id)
        {
            ApplicationSessionStore store = new ApplicationSessionStore(HttpContext.Session);

            return(View(store.GetApplication().SupportingWorks[Id]));
        }