Exemple #1
0
        public async void SendMail(Recomendation recomendation, string templatePath, string runnerName)
        {
            var message = new MimeKit.MimeMessage();

            message.From.Add(new MimeKit.MailboxAddress("Mr Recomender", "*****@*****.**"));
            message.To.Add(new MimeKit.MailboxAddress("testMailBox", "*****@*****.**"));
            message.Subject = "Recomendation - " + recomendation.title + ". Delivered by: " + runnerName;

            var    bodyBuilder = new BodyBuilder();
            string templateContent;

            //TODO: investigate better way of cross platform file path resolving
            using (StreamReader SourceReader = System.IO.File.OpenText($"{templatePath}{Path.DirectorySeparatorChar}email.tmpl"))
            {
                templateContent = SourceReader.ReadToEnd();
            }
            StringBuilder myStringBuilder = new StringBuilder();

            myStringBuilder.Append("<h2>Here is a book recomendation, please enjoy</h2>");
            myStringBuilder.Append("<h3>Brought to you by our recomendations team!</h3>");
            myStringBuilder.Append("<dl>");
            myStringBuilder.Append("<dt>Title</dt>");
            myStringBuilder.Append($"<dd>{recomendation.title}</dd>");
            myStringBuilder.Append("<dt>Author</dt>");
            myStringBuilder.Append($"<dd>{recomendation.author}</dd>");
            myStringBuilder.Append("<dt>language</dt>");
            myStringBuilder.Append($"<dd>{recomendation.language}</dd>");
            myStringBuilder.Append("<dt>Page Count</dt>");
            myStringBuilder.Append($"<dd>{recomendation.pages}</dd>");
            myStringBuilder.Append("<dt>Wiki</dt>");
            myStringBuilder.Append($"<dd><a href='{recomendation.link}' />{recomendation.link}</dd>");
            myStringBuilder.Append("</dl>");

            bodyBuilder.HtmlBody = string.Format(templateContent,
                                                 GetStyleText(templatePath),
                                                 myStringBuilder.ToString()
                                                 );

            message.Body = bodyBuilder.ToMessageBody();

            using (var mailClient = new SmtpClient())
            {
                await mailClient.ConnectAsync(MAIL_HOST, MAIL_PORT, SecureSocketOptions.None);

                await mailClient.SendAsync(message);

                await mailClient.DisconnectAsync(true);
            }
        }
        //public ActionResult Create( RecommendationViewModel RVM,int id)
        //{
        //    //Recomendation R = new Recomendation();


        //    //R.IdRecom = RVM.IdRecom;
        //    //R.ParticipantId = int.Parse(User.Identity.GetUserId());

        //    //R.MailRecomd = "test";
        //    //R.RefRecommendation = RVM.RefRecommendation;
        //    //R.EtaRec = Domain.Entities.EtatRecom.inprogress;
        //    //R.EventId = RVM.EventId=id;
        //    //SendingMail("*****@*****.**", R.MailRecomd, "recommendation", "test recommendation ");
        //    //RS.Add(R);
        //    //RS.Commit();
        //    //return View(RVM);
        //}



        public ActionResult Create(RecommendationViewModel rvm, int id)
        {
            Recomendation r = new Recomendation();

            r.ID               = rvm.ID;
            r.IdParticipant    = int.Parse(User.Identity.GetUserId());
            r.IdEvent          = rvm.IdEvent = id;
            r.Nom              = us.GetUserById(r.IdParticipant).FirstName;
            r.Prenom           = us.GetUserById(r.IdParticipant).LastName;
            r.EmailParticipent = rvm.EmailParticipent;
            SendingMail("*****@*****.**", r.EmailParticipent, "[Recommendation for an Event]", "check this link :http://localhost:59686/Evenement/details/" + id);
            RS.Add(r);
            RS.Commit();

            return(RedirectToAction("DetailsParticipant", "Evenement"));
        }
Exemple #3
0
        public async Task <List <SimpleTrack> > ObterPorGenero(string genero)
        {
            var tracks = new List <FullTrack>();

            var recommendation = new Recomendation();

            try
            {
                var token = await _auth.ObterToken();

                var _client  = new RestClient("https://api.spotify.com/v1");
                var _request = new RestRequest(Method.GET);

                _request.Resource = $"/recommendations";

                _request.AddParameter("market", "BR");
                _request.AddParameter("seed_genres", genero.ToLower());

                _request.AddHeader("Authorization", $"Bearer {token}");

                var response = await _client.ExecuteAsync(_request);

                if (response.IsSuccessful)
                {
                    recommendation = JsonConvert.DeserializeObject <Recomendation>(response.Content);
                }
                else
                {
                    recommendation.ErroItem = JsonConvert.DeserializeObject <ErroItem>(response.Content);
                }
            }
            catch (Exception ex)
            {
            }

            return(recommendation.Tracks);
        }
 public void Delete(Recomendation Recomendation)
 {
     _context.Recomendation.Remove(Recomendation);
     _context.SaveChanges();
 }
 public void Update(Recomendation Recomendation)
 {
     _context.Recomendation.Update(Recomendation);
     _context.SaveChanges();
 }
 public void Create(Recomendation Recomendation)
 {
     _context.Recomendation.Add(Recomendation);
     _context.SaveChanges();
 }