示例#1
0
        // GET: SponsorEvents/Create
        public ActionResult Create()
        {
            try
            {
                if (User.IsInRole("Admin"))
                {
                    if (ModelState.IsValid)
                    {
                        var items    = Session[""] as List <Sponsor>;
                        var newEvent = Session[""] as Event;

                        if (newEvent.EventId < 1 || items.Count < 1)
                        {
                            return(RedirectToAction("Error404", "Home"));
                        }

                        var newRecords = _repo.SaveSponsorInEvent(items, newEvent.EventId);
                        if (newRecords == null)
                        {
                            return(RedirectToAction("Error404", "Home"));
                        }

                        //Change the Redirect to Action
                        return(RedirectToAction("Index", "Locations"));
                    }
                }

                return(RedirectToAction("Login", "Account"));
            }
            catch (Exception ex)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.ToString()));
            }
        }
示例#2
0
        public ActionResult Photo(HttpPostedFileBase photo)
        {
            if (User.IsInRole("Admin"))
            {
                var EventDetails        = Session["Event"] as Event;
                var ArtistListForEvent  = Session["ArtistListForEvent"] as List <Artist>;
                var EventLocation       = Session["EventLocation"] as Location;
                var SponsorListForEvent = Session["SponsorListForEvent"] as List <Sponsor>;

                //var EventWallpaper = Session["EventWallpaper"] as HttpPostedFileBase;

                if (EventDetails == null || EventLocation == null || SponsorListForEvent == null || ArtistListForEvent == null)
                {
                    return(RedirectToAction("Error404", "Home"));
                }

                var NewEvent = new Event()
                {
                    Description = EventDetails.Description,
                    EventDate   = EventDetails.EventDate,
                    Name        = EventDetails.Name,
                    LocationId  = EventLocation.LocationId,
                    DtAdded     = DateTime.UtcNow,
                    Status      = "Active"
                };
                db.Events.Add(NewEvent);
                db.SaveChanges();

                var myPhoto = new Photo();
                myPhoto.ContentType = photo.ContentType;
                myPhoto.Content     = new byte[photo.ContentLength];
                myPhoto.EventId     = NewEvent.EventId;
                photo.InputStream.Read(myPhoto.Content, 0, photo.ContentLength);
                db.Photos.Add(myPhoto);
                db.SaveChanges();

                var newArtistList = _ArtistEventRepo.SaveArtistInEvent(ArtistListForEvent, NewEvent.EventId);
                if (newArtistList.Count < 0)
                {
                    return(RedirectToAction("Error404", "Home"));
                }

                var newSponsorList = _SponsorEventRepo.SaveSponsorInEvent(SponsorListForEvent, NewEvent.EventId);
                if (newSponsorList.Count() < 0)
                {
                    return(RedirectToAction("Error404", "Home"));
                }

                Session.Remove("Event");
                Session.Remove("ArtistListForEvent");
                Session.Remove("EventLocation");
                Session.Remove("SponsorListForEvent");

                return(RedirectToAction("Details", "Events", new { id = NewEvent.EventId }));
            }
            return(RedirectToAction("Login", "Account"));
        }