Пример #1
0
        public async Task <IActionResult> EditWhatDoWeOffer(OfferEditViewModel offerView)
        {
            if (offerView.OfferImage != null)
            {
                using (var memoryStream = new MemoryStream())
                {
                    await offerView.OfferImage.CopyToAsync(memoryStream);

                    offerView.Offer.Image         = memoryStream.ToArray();
                    offerView.Offer.ImageMimeType = offerView.OfferImage.ContentType;
                }
            }
            if (ModelState.IsValid)
            {
                var category = new WhatDoWeOffer
                {
                    Title       = offerView.Offer.Title,
                    Description = offerView.Offer.Description,
                    Image       = offerView.Offer.Image
                };

                offerRepository.SaveOffer(offerView.Offer);
                TempData["message"] = $"{offerView.Offer.Title} has been saved";
                return(RedirectToAction("InformationList"));
            }
            else
            {
                // there is something wrong with the data values
                return(View(offerView));
            }
        }
Пример #2
0
        public IActionResult DeleteOffer(int offerId)
        {
            WhatDoWeOffer deletedOffer = offerRepository.DeleteOffer(offerId);

            if (deletedOffer != null)
            {
                TempData["message"] = $"{deletedOffer.Title} was deleted";
            }
            return(RedirectToAction("InformationList"));
        }
Пример #3
0
        public FileContentResult GetImageOffer(WhatDoWeOffer item)
        {
            WhatDoWeOffer offer = offerRepository.Offers
                                  .FirstOrDefault(g => g.Id == item.Id);

            if (offer != null)
            {
                return(File(offer.Image, offer.ImageMimeType));
            }
            else
            {
                return(null);
            }
        }