public ImageInfoEntity AddImageInfo(ImageInfoInputModel imageInfo, string freeUrl, string freeSuccess)
        {
            // checking if something went wrong in email sending process
            bool ok        = true;
            bool emailSent = false;

            if (freeSuccess.ToLower() == "sent")
            {
                emailSent = true;
            }
            else
            {
                ok = false;
            }

            // Create the entity to add to the database.
            ImageInfoEntity newEnt = new ImageInfoEntity()
            {
                imageGUID               = imageInfo.imageGUID,
                email                   = imageInfo.email,
                timeStamp               = imageInfo.timeStamp,
                hasFreeEmailBeenSent    = emailSent,
                hasPremiumEmailBeenSent = false,
                success                 = ok,
                hasImageBeenBought      = false,
                premiumUrl              = imageInfo.Url,
                freeUrl                 = freeUrl
            };

            _context.imageInfo.Add(newEnt);
            _context.SaveChanges();
            return(newEnt);
        }
        // Creates URL for the low-res image with ads.
        public string GetLowresImgUrlWithAd(ImageInfoInputModel body)
        {
            int index      = IndexOfNth(body.Url, '/', 6) + 1;
            var freeImgUrl = body.Url.Insert(index, "t_SeptAD/");

            return(freeImgUrl);
        }
        public async Task <ImageInfoEntity> AddImageInfo(ImageInfoInputModel imageInfo, string freeUrl, HttpContext context)
        {
            _authService.ValidateAuthorizationPrivilege(context, whoHasAuth);
            string succsess = await _emailService.SendEmailWithTemplate(imageInfo, freeUrl);

            return(_imageRepository.AddImageInfo(imageInfo, freeUrl, succsess));
        }
Example #4
0
        public async Task <IActionResult> CreateNewImageInfo([FromBody] ImageInfoInputModel body)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Model is not properly formatted."));
            }
            string lowresUrl = _imageService.GetLowresImgUrlWithAd(body);
            var    entity    = await _imageService.AddImageInfo(body, lowresUrl, this.HttpContext);

            return(CreatedAtRoute("GetImageInfoById", new { id = entity.ID }, null));
        }
        // býr til email með fríu myndinni til að senda.
        public async Task <string> SendEmailWithTemplate(ImageInfoInputModel imageInfo, string freeUrl)
        {
            // populate the MailChimp merge tags.
            Dictionary <string, string> dict = new Dictionary <string, string>()
            {
                { "IMAGEURL", freeUrl },
                { "CURRENT_YEAR", "2019" },
                { "COMPANY", "Selfie Station" }
            };

            //EmailAddress to send to
            EmailAddress address = new EmailAddress();

            address.Type  = "to";
            address.Email = imageInfo.email;

            //Adding email address to list
            List <EmailAddress> toEmail = new List <EmailAddress>();

            toEmail.Add(address);

            //Creating the email to send.
            EmailMessage emailMsg = new EmailMessage();

            emailMsg.FromName  = "Selfie Station";
            emailMsg.FromEmail = "*****@*****.**";
            emailMsg.To        = toEmail;
            emailMsg.Subject   = "Your Selfie Station Photo";

            // send with template
            string template = "SelfieStationFreeImgTag";

            var success = await SendEmail(emailMsg, address, dict, template);

            return(success);
        }