예제 #1
0
        public ActionResult Create(FormCollection collection, Location location, string Upload)
        {
            try
            {
                ImageController   ac          = new ImageController();
                List <UploadFile> uploadFiles = ac.GenerateAttachFileCollectionID(collection, "Location");

                if (Upload != null)
                {
                    ImageUploadToServer();
                    if (uploadFiles != null)
                    {
                        ModelStateSetting(uploadFiles, "Location");
                    }
                    return(View());
                }

                foreach (UploadFile uploadFile in uploadFiles)
                {
                    LocationUploadFile auf = new LocationUploadFile();
                    auf.UploadFileID = uploadFile.ID;
                    location.LocationUploadFiles.Add(auf);
                }

                _entities.AddToLocations(location);
                _entities.SaveChanges();

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
        public ActionResult Edit(int id, FormCollection collection, string Upload)
        {
            var announcement = _entities.Announcements.Single(a => a.ID == id);

            try
            {
                ImageController   ac          = new ImageController();
                List <UploadFile> uploadFiles = ac.GenerateAttachFileCollectionID(collection, "Announcement");

                if (Upload != null)
                {
                    ImageUploadToServer();

                    if (uploadFiles != null)
                    {
                        ModelStateSetting(uploadFiles, "Announcement");
                    }

                    UpdateModel(announcement, "Announcement");
                    var viewModel = new AnnouncementViewModel()
                    {
                        Announcement = announcement,
                    };
                    return(View(viewModel));
                }

                List <AnnouncementUploadFile> aUploadFiles = announcement.AnnouncementUploadFiles.ToList();
                foreach (AnnouncementUploadFile aUploadFile in aUploadFiles)
                {
                    announcement.AnnouncementUploadFiles.Remove(aUploadFile);
                }

                foreach (UploadFile uploadFile in uploadFiles)
                {
                    AnnouncementUploadFile auf = new AnnouncementUploadFile();
                    auf.UploadFileID = uploadFile.ID;
                    announcement.AnnouncementUploadFiles.Add(auf);
                }

                announcement.AnnounceDate = DateTime.Parse(collection.GetValues("Announcement.AnnounceDate")[0]);
                announcement.Description  = collection.GetValues("Announcement.Description")[0];
                announcement.IsPublic     = bool.Parse(collection.GetValues("Announcement.IsPublic")[0]);
                announcement.Name         = collection.GetValues("Announcement.Name")[0];
                announcement.StaticURL    = collection.GetValues("Announcement.StaticURL")[0];
                //announcement. = collection.Get("Announcement.URLChecked");

                //UpdateModel(announcement, "Announcement");
                _entities.SaveChanges();

                return(RedirectToAction("Index", new { announceGroupID = announcement.AnnounceGroupID }));
            }
            catch
            {
                return(View());
            }
        }
예제 #3
0
        public ActionResult Edit(int id, FormCollection collection, string Upload)
        {
            var aEvent = _entities.Events.Single(a => a.ID == id);

            try
            {
                ImageController   ac          = new ImageController();
                List <UploadFile> uploadFiles = ac.GenerateAttachFileCollectionID(collection, "Event");

                if (Upload != null)
                {
                    ImageUploadToServer();

                    if (uploadFiles != null)
                    {
                        ModelStateSetting(uploadFiles, "Event");
                    }

                    UpdateModel(aEvent, "Event");
                    var viewModel = new EventViewModel()
                    {
                        Event      = aEvent,
                        Locations  = _entities.Locations.ToList(),
                        EventTypes = (from r in _entities.EventTypes where r.ID != 2 && r.ID != 3 select r).ToList(),
                    };
                    return(View(viewModel));
                }

                List <EventUploadFile> aEventUploadFiles = aEvent.EventUploadFiles.ToList();
                foreach (EventUploadFile aEventUploadFile in aEventUploadFiles)
                {
                    aEvent.EventUploadFiles.Remove(aEventUploadFile);
                }

                foreach (UploadFile uploadFile in uploadFiles)
                {
                    EventUploadFile auf = new EventUploadFile();
                    auf.UploadFileID = uploadFile.ID;
                    aEvent.EventUploadFiles.Add(auf);
                }

                UpdateModel(aEvent, "Event");
                _entities.SaveChanges();

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
예제 #4
0
        public ActionResult Edit(int id, FormCollection collection, string Upload)
        {
            var location = _entities.Locations.Single(a => a.ID == id);

            try
            {
                ImageController   ac          = new ImageController();
                List <UploadFile> uploadFiles = ac.GenerateAttachFileCollectionID(collection, "Location");

                if (Upload != null)
                {
                    ImageUploadToServer();

                    if (uploadFiles != null)
                    {
                        ModelStateSetting(uploadFiles, "Location");
                    }

                    UpdateModel(location, "Location");
                    var viewModel = new LocationViewModel()
                    {
                        Location = location,
                    };
                    return(View(viewModel));
                }

                List <LocationUploadFile> aLocationUploadFiles = location.LocationUploadFiles.ToList();
                foreach (LocationUploadFile aLocationUploadFile in aLocationUploadFiles)
                {
                    location.LocationUploadFiles.Remove(aLocationUploadFile);
                }

                foreach (UploadFile uploadFile in uploadFiles)
                {
                    LocationUploadFile auf = new LocationUploadFile();
                    auf.UploadFileID = uploadFile.ID;
                    location.LocationUploadFiles.Add(auf);
                }

                UpdateModel(location, "Location");
                _entities.SaveChanges();

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
예제 #5
0
        private void ImageUploadToServer()
        {
            HttpPostedFileBase file = Request.Files["fileUpload"];

            if (string.IsNullOrEmpty(file.FileName))
            {
                throw new Exception("Please select a file!");
            }

            ImageController ic         = new ImageController();
            string          savePath   = "../images/UploadFiles";
            string          filePath   = Path.Combine(HttpContext.Server.MapPath(savePath), Path.GetFileName(file.FileName));
            UploadFile      uploadFile = ic.ImageUpload(file, filePath, savePath);

            ViewData["CurrentUploadFile"] = uploadFile;
        }
        public ActionResult Create(FormCollection collection, Announcement announcement, string Upload)
        {
            MembershipUser mu = Membership.GetUser();

            try
            {
                ImageController   ac          = new ImageController();
                List <UploadFile> uploadFiles = ac.GenerateAttachFileCollectionID(collection, "Announcement");

                if (Upload != null)
                {
                    ImageUploadToServer();
                    if (uploadFiles != null)
                    {
                        ModelStateSetting(uploadFiles, "Announcement");
                    }
                    var viewModel = new AnnouncementViewModel
                    {
                        Announcement    = announcement,
                        AnnouncementIDs = new List <int>(),
                    };
                    viewModel.AnnouncementIDs.Add((int)TempData["AnnounceGroupID"]);
                    return(View(viewModel));
                }

                foreach (UploadFile uploadFile in uploadFiles)
                {
                    AnnouncementUploadFile auf = new AnnouncementUploadFile();
                    auf.UploadFileID = uploadFile.ID;
                    announcement.AnnouncementUploadFiles.Add(auf);
                }

                announcement.AnnouncerID     = (Guid)(mu.ProviderUserKey);
                announcement.AnnounceGroupID = (int)TempData["AnnounceGroupID"];

                _entities.AddToAnnouncements(announcement);
                _entities.SaveChanges();

                return(RedirectToAction("Index", new { announceGroupID = (int)TempData["AnnounceGroupID"] }));
            }
            catch
            {
                return(View());
            }
        }
예제 #7
0
        private UploadFile ImageUploadToServer(int productID)
        {
            HttpPostedFileBase file = Request.Files["fileUpload"];

            if (string.IsNullOrEmpty(file.FileName))
            {
                throw new Exception("Please select a file!");
            }

            string savePath = "../images/SMProducts";

            if (productID > 0)
            {
                savePath = "../" + savePath;
            }
            string          filePath   = Path.Combine(HttpContext.Server.MapPath(savePath), Path.GetFileName(file.FileName));
            ImageController ic         = new ImageController();
            UploadFile      uploadFile = ic.ImageUpload(file, filePath, savePath);

            ViewData["CurrentUploadFile"] = uploadFile;
            return(uploadFile);
        }
예제 #8
0
        public ActionResult Create(FormCollection collection, Event Event, string Upload)
        {
            MembershipUser mu = Membership.GetUser();

            try
            {
                ValidateEvent(Event);
                if (!ModelState.IsValid)
                {
                    throw new Exception();//ModelState["Event.StartDateTime"].Errors.Last().ErrorMessage);
                }

                ImageController ac = new ImageController();

                List <UploadFile> uploadFiles = ac.GenerateAttachFileCollectionID(collection, "Event");

                if (Upload != null)
                {
                    ImageUploadToServer();
                    if (uploadFiles != null)
                    {
                        ModelStateSetting(uploadFiles, "Event");
                    }
                    var viewModel = new EventViewModel()
                    {
                        Event      = Event,
                        Locations  = _entities.Locations.ToList(),
                        EventTypes = (from r in _entities.EventTypes where r.ID != 2 && r.ID != 3 select r).ToList(),
                    };
                    return(View(viewModel));
                }

                foreach (UploadFile uploadFile in uploadFiles)
                {
                    EventUploadFile auf = new EventUploadFile();
                    auf.UploadFileID = uploadFile.ID;
                    Event.EventUploadFiles.Add(auf);
                }

                Event.OrganizerNameID = (Guid)(mu.ProviderUserKey);

                //GenerateEventPrices(Event);

                _entities.AddToEvents(Event);
                _entities.SaveChanges();


                if (Event.EventTypeID == 1)
                {
                    Event             = (from r in _entities.Events select r).OrderByDescending(x => x.ID).First();
                    TempData["Event"] = Event;

                    return(RedirectToAction("ScheduleModelSelect", "EventSchedule"));
                }
                else
                {
                    EventScheduleController esc = new EventScheduleController();
                    esc.GenerateEventSchedules(Event);

                    return(RedirectToAction("Index"));
                }
            }
            catch
            {
                var viewModel = new EventViewModel()
                {
                    Event      = new Event(),
                    Locations  = _entities.Locations.ToList(),
                    EventTypes = (from r in _entities.EventTypes where r.ID != 2 && r.ID != 3 select r).ToList(),
                };
                //viewModel.LocalRetreatScheduleModelSelectLists = GetScheduleSelectLists();

                return(View(viewModel));
            }
        }