コード例 #1
0
        public void Update(PriceFollowerDTO model)
        {
            var entity = uOW.PriceFollowerRepo.GetByID(model.id);
            var item   = Mapper.Map <PriceFollower>(model);

            entity.Price  = item.Price;
            entity.Status = item.Status;

            uOW.Save();
        }
コード例 #2
0
        public void Insert(PriceFollowerDTO model)
        {
            var item = Mapper.Map <PriceFollower>(model);

            item.Status = FollowStatus.NotSend;
            var followPrices = uOW.PriceFollowerRepo.All.Where(x => x.Good_Id == model.Good_Id && x.User_Id == model.User_Id).ToList();

            if (!followPrices.Any())
            {
                uOW.PriceFollowerRepo.Insert(item);
                uOW.Save();
            }
        }
コード例 #3
0
        /// <summary>
        /// Method to send message via email about price fall
        /// </summary>
        /// <param name="model"></param>
        /// <param name="price"></param>
        /// <param name="email"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public bool SendEmail(PriceFollowerDTO model, decimal?price, string email, string password)
        {
            var good = uOW.GoodRepo.GetByID(model.Good_Id);
            var user = uOW.UserRepo.GetByID(model.User_Id);

            var _email = email;
            var pass   = password;

            try
            {
                using (SmtpClient client = new SmtpClient())
                {
                    client.EnableSsl             = true;
                    client.Port                  = 587;
                    client.Host                  = "smtp.gmail.com";
                    client.UseDefaultCredentials = false;

                    client.Credentials    = new NetworkCredential(_email, pass);
                    client.DeliveryMethod = SmtpDeliveryMethod.Network;


                    var         from     = _email;
                    var         to       = user.Email;
                    MailMessage message  = new MailMessage(from, to);
                    string      mailBody = "Hello " + user.UserName + ". Do you now that the price of " + good.Name + " fell." +
                                           " Now the price is just " + good.Price + ". Follow this link for details:" + good.UrlLink;

                    var htmlView = AlternateView.CreateAlternateViewFromString(mailBody + "<br/><br/><img src=" + good.ImgLink + "> ", null, "text/html");
                    //Add image to HTML version
                    message.Subject = "Sales on WSDP";
                    message.AlternateViews.Add(htmlView);
                    message.IsBodyHtml = true;

                    client.Send(message);
                }

                return(true);
            }

            catch (Exception ex)
            {
                logger.Error(ex.Message);
            }

            return(false);
        }
コード例 #4
0
 public void FollowGoodPrice(string good_Id, string user_Id, string price)
 {
     if (Request.IsAuthenticated)
     {
         var model = new PriceFollowerDTO()
         {
             Good_Id = Convert.ToInt32(good_Id),
             User_Id = Convert.ToInt32(user_Id),
             Price   = Convert.ToDecimal(price)
         };
         followPriceManager.Insert(model);
     }
     else
     {
         RedirectToAction("SignUp", "Account");
     }
 }