示例#1
0
        public ActionResult Send(string receivermail, string subject, string message, string cCMail)
        {
            SessionKontrol();
            if (_users != null)
            {
                var emailsettings = _EmailSettingsServices.Get(1);

                bool isItSended = _MailHelper.Send(receivermail, subject, message, cCMail, emailsettings.Username, emailsettings.Password, emailsettings.Host, emailsettings.Port, emailsettings.Mail);

                if (isItSended)
                {
                    EmailHistoryViewModel ehvm = new EmailHistoryViewModel();
                    ehvm.ReceiverMail = receivermail;
                    ehvm.Subject      = subject;
                    ehvm.Message      = message;

                    _EmailHistoryServices.Add(ehvm);
                    _unitOfWork.SaveChanges();
                }


                return(RedirectToAction("Index", "Email"));
            }
            else
            {
                return(RedirectToAction("Index", "Login"));
            }
        }
示例#2
0
        public HttpResponseMessage Post(MessageDTO message)
        {
            HttpResponseMessage response = null;

            if (message == null ||
                message.CategoryId < 1 ||
                !context.Categories.Any(c => c.Id == message.CategoryId) ||
                string.IsNullOrEmpty(message.Content) ||
                string.IsNullOrEmpty(message.Title) ||
                string.IsNullOrEmpty(message.UserId))
            {
                response = new HttpResponseMessage(HttpStatusCode.BadRequest);
                return(response);
            }

            User userDb = context.Users.SingleOrDefault(u => u.Id == message.UserId);

            if (userDb == null)
            {
                response = new HttpResponseMessage(HttpStatusCode.Unauthorized);
                return(response);
            }

            List <Student> studentsDb = context.Students
                                        .Where(s => s.Categories.Any(c => c.CategoryId == message.CategoryId))
                                        .ToList();

            Message messageDb = new Message()
            {
                Title   = message.Title,
                Content = message.Content,
                Emails  = studentsDb.Select(s => s.UserName).ToList(),
                AddedAt = DateTime.Now,
                UserId  = message.UserId,
                SendAt  = DateTime.Now
            };

            userDb.Messages.Add(messageDb);
            context.SaveChanges();

            foreach (string email in studentsDb.Select(s => s.UserName))
            {
                MailHelpers.Send(email, messageDb.Title, messageDb.Content);
            }

            response         = new HttpResponseMessage(HttpStatusCode.OK);
            response.Content = new StringContent(studentsDb.Count().ToString(), Encoding.UTF8);

            return(response);
        }
示例#3
0
        public IActionResult Index(string Name, string PostalCode, string Street, string Email, string City, string LastName, string FirstName, string Subject)
        {
            if (ModelState.IsValid)
            {
                string content = "Name: " + Name;
                content += "<br>Gata: " + Street;
                content += "<br>Stad: " + City;
                content += "<br>Postnummer: " + PostalCode;
                content += "<br>E-post: " + Email;
                if (MailHelpers.Send(Email, "*****@*****.**", Subject, content))
                {
                    ViewBag.msg     = "Tack för ditt meddelande";
                    ViewBag.Section = "s2";
                }
                else
                {
                    ViewBag.msg     = "Meddelandet kunde inte skickas";
                    ViewBag.Section = "s2";
                }



                ViewBag.Section = "s2";
                return(Index());
            }
            // Get brokers

            var brokers = _context.Broker;

            List <Broker> Brokers = new List <Broker>();

            foreach (var item in brokers)
            {
                Broker brok = new Broker()
                {
                    BrokerId    = item.BrokerId,
                    FirstName   = item.fullname,
                    Phonenumber = item.Phonenumber,
                    Email       = item.Email,
                    Title       = item.Title,
                    Image       = item.Image
                };
                Brokers.Add(brok);
            }

            ViewBag.BrokerList = Brokers;
            // ALL REGULAR IMAGES
            // Get hero images
            var getImages = _context.Image;
            var homes     = _context.Homes;
            var last      = (from c in _context.Homes select c.HomeId).Max();


            IQueryable <project.Models.Homes> firstThree = homes.OrderByDescending(t => t.PublishDate).Where(t => t.deleted != true).Take(3);
            IQueryable <project.Models.Homes> lastThree  = homes.OrderByDescending(t => t.PublishDate).Where(t => t.deleted != true).Skip(3).Take(3);

            ViewBag.firstThree = firstThree;
            ViewBag.lastThree  = lastThree;
            ViewBag.Section    = "s2";
            return(Index());
        }