Example #1
0
        public async Task <IActionResult> Edit(int id,
                                               [Bind("SponsorId,CompanyName,SponsorLevel,Bio,TwitterHandle,WebsiteUrl,ImageFile,PointOfContact,EmailAddress,PhoneNumber")] SponsorViewModel sponsorVM)
        {
            if (ModelState.IsValid)
            {
                if (id != sponsorVM.SponsorId)
                {
                    return(NotFound());
                }

                var sponsor = await _sponsorBL.GetSponsor(sponsorVM.SponsorId);

                sponsor.CompanyName    = sponsorVM.CompanyName;
                sponsor.SponsorLevel   = sponsorVM.SponsorLevel;
                sponsor.Bio            = sponsorVM.Bio;
                sponsor.TwitterHandle  = sponsorVM.TwitterHandle;
                sponsor.WebsiteUrl     = sponsorVM.WebsiteUrl;
                sponsor.PointOfContact = sponsorVM.PointOfContact;
                sponsor.EmailAddress   = sponsorVM.EmailAddress;
                sponsor.PhoneNumber    = sponsorVM.PhoneNumber;

                // Convert the image to a byte array, reduce the size to 500px x 500px
                // and store it in the database
                if (sponsorVM.ImageFile != null &&
                    sponsorVM.ImageFile.ContentType.ToLower().StartsWith("image/") &&
                    sponsorVM.ImageFile.Length <= SponsorViewModel.MaxImageSize)
                {
                    MemoryStream ms = new MemoryStream();
                    sponsorVM.ImageFile.OpenReadStream().CopyTo(ms);

                    sponsor.Image
                        = _sponsorBL.ResizeImage(ms.ToArray());
                }

                var result = await _sponsorBL.UpdateSponsor(sponsor);

                if (result == false)
                {
                    return(NotFound());
                }
                else
                {
                    return(RedirectToAction(nameof(Index)));
                }
            }

            ViewBag.SponsorshipLevels = SponsorLevel.GetSponsorshipLevels();
            return(View(sponsorVM));
        }
Example #2
0
        public async Task <IActionResult> Create([Bind("SponsorId,CompanyName,SponsorLevel,Bio,TwitterHandle,WebsiteUrl,ImageFile,PointOfContact,EmailAddress,PhoneNumber")] SponsorViewModel sponsorVM)
        {
            if (ModelState.IsValid)
            {
                var theEvent = await _eventBL.GetActiveEvent();

                if (theEvent != null)
                {
                    var sponsor = new Sponsor
                    {
                        SponsorId      = sponsorVM.SponsorId,
                        CompanyName    = sponsorVM.CompanyName,
                        SponsorLevel   = sponsorVM.SponsorLevel,
                        Bio            = sponsorVM.Bio,
                        TwitterHandle  = sponsorVM.TwitterHandle,
                        WebsiteUrl     = sponsorVM.WebsiteUrl,
                        PointOfContact = sponsorVM.PointOfContact,
                        EmailAddress   = sponsorVM.EmailAddress,
                        PhoneNumber    = sponsorVM.PhoneNumber,
                        EventId        = theEvent.EventId
                    };

                    // Convert the image to a byte array, reduce the size to 500px x 500px
                    // and store it in the database
                    if (sponsorVM.ImageFile != null &&
                        sponsorVM.ImageFile.ContentType.ToLower().StartsWith("image/") &&
                        sponsorVM.ImageFile.Length <= SponsorViewModel.MaxImageSize)
                    {
                        MemoryStream ms = new MemoryStream();
                        sponsorVM.ImageFile.OpenReadStream().CopyTo(ms);

                        sponsor.Image
                            = _sponsorBL.ResizeImage(ms.ToArray());
                    }

                    await _sponsorBL.CreateSponsor(sponsor);

                    return(RedirectToAction(nameof(Index)));
                }
            }

            ViewBag.SponsorshipLevels = SponsorLevel.GetSponsorshipLevels();
            return(View(sponsorVM));
        }
Example #3
0
        // GET: Sponsors/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            if (!id.HasValue)
            {
                return(NotFound());
            }

            if (!await _sponsorBL.SponsorExists(id.Value))
            {
                return(NotFound());
            }

            var sponsorVM = await _sponsorBL.GetSponsorViewModel(id.Value);

            if (sponsorVM == null)
            {
                return(NotFound());
            }

            ViewBag.SponsorshipLevels = SponsorLevel.GetSponsorshipLevels();
            return(View(sponsorVM));
        }
        // TODO Sponsor levels are not currently tied to EventIds
        public IList <SponsorLevel> GetSponsorLevels()
        {
            var sponsorLevel = SponsorLevel.GetSponsorshipLevels();

            return(sponsorLevel);
        }
Example #5
0
 // GET: Sponsors/Create
 public IActionResult Create()
 {
     ViewBag.SponsorshipLevels = SponsorLevel.GetSponsorshipLevels();
     return(View());
 }