示例#1
0
 public EmailController()
 {
     _MailHelper             = new MailHelpers();
     _EmailSettingsServices  = new EmailSettingsServices(_unitOfWork);
     _EmailTemplatesServices = new EmailTemplatesServices(_unitOfWork);
     _EmailHistoryServices   = new EmailHistoryServices(_unitOfWork);
 }
示例#2
0
        public bool SendMail(string email, string firstname, string lastname)
        {
            bool        flgResult   = false;
            MailHelpers mailHelpers = new MailHelpers();

            mailHelpers.SendMailWelcome("*****@*****.**", "Trung", "Tran");
            return(true);
        }
示例#3
0
        public ActionResult ForgotPassword(ForgotViewModel model)
        {
            MailHelpers mail        = new MailHelpers();
            string      newPassword = GenerateDefaultPassword();

            UserContext.UpdatePassword(model.Email, newPassword);
            if (mail.SendMailResetPassword(model.Email, newPassword))
            {
                return(RedirectToAction("Index", "Home"));
            }
            return(RedirectToAction("ForgotPassword", "Authorization"));
        }
示例#4
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);
        }
        protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, PermissionRequirement requirement)
        {
            if (requirement is ProtectedHealthInformationRequirement)
            {
                base.HandleRequirementAsync(context, requirement).ExecuteSynchronously();
                if (context.HasSucceeded)
                {
                    if (MailHelpers.IsEmailAddressPartOfHostname(Current.User.Email, Current.Tenant.TenantSettings.ProtectedHealthInformationViewableByEmailAddressHostnames))
                    {
                        goto Done;
                    }
                    context.Fail();
                }
            }
Done:
            return(Task.FromResult(0));
        }
示例#6
0
        private void AsignarDatos(ECronogramas cronograma)
        {
            StringBuilder info = new StringBuilder();

            info.Append("Código: ").Append(cronograma.EVehiculo.Id_vehiculo);
            info.Append(" - Placa: ").Append(cronograma.EVehiculo.Placa).Append(Environment.NewLine);
            info.Append("Conductor: ").Append(cronograma.EVehiculo.Chofer).Append(Environment.NewLine);
            info.Append("Modelo: ").Append(cronograma.EVehiculo.Modelo);
            info.Append(" - Color: ").Append(cronograma.EVehiculo.Color);

            this.txtInformacion.Text = info.ToString();
            this.txtCorreo.Text      = cronograma.EVehiculo.Correo_chofer;
            if (MailHelpers.EmailValidation(this.txtCorreo.Text))
            {
                this.errorProvider1.SetError(this.txtCorreo, "El correo electrónico no tiene un formato correcto");
            }
            else
            {
                this.errorProvider1.Clear();
            }
            this.dateEstado.MinDate = DateTime.Now;
        }
示例#7
0
        public ActionResult RegisterPost(RegisterVM vm)
        {
            var recaptchaHelper = this.GetRecaptchaVerificationHelper();

            if (string.IsNullOrEmpty(recaptchaHelper.Response))
            {
                //This means the captcha had a empty response.
                ModelState.AddModelError("CaptchaResponse", "Please complete the captcha.");
            }

            var recaptchaResult = recaptchaHelper.VerifyRecaptchaResponse();

            if (recaptchaResult != RecaptchaVerificationResult.Success)
            {
                ModelState.AddModelError("CaptchaResponse", "Invalid captcha response.");
            }

            if (!string.Equals(vm.Password, vm.PasswordCheck))
            {
                ModelState.AddModelError("Password", "Passwords do not match ");
            }

            if (MailHelpers.CheckIfValidEmail(vm.MailAdress))
            {
                var userExists = Context.Users.Any(x => x.UserName == vm.UserName);
                var mailExists = Context.Users.Any(x => x.Mail == vm.MailAdress);
                if (!mailExists && !userExists)
                {
                    Context.Users.Add(new User
                    {
                        UserName         = vm.UserName,
                        Mail             = vm.MailAdress,
                        Password         = Hashing.Hash(vm.Password),
                        RegisterDate     = DateTime.Now,
                        FirstName        = vm.FirstName,
                        LastName         = vm.LastName,
                        LastLoginAttempt = DateTime.Now
                    });
                }
                else
                {
                    if (mailExists)
                    {
                        ModelState.AddModelError("MailAdress", "Email already in use.");
                    }

                    if (userExists)
                    {
                        ModelState.AddModelError("UserName", "Username already in use.");
                    }
                }

                if (ModelState.IsValid && (vm.Password == vm.PasswordCheck))
                {
                    Context.SaveChanges();

                    //Add the user to the specified group if the person was invited while a groupadmin was inviting people
                    var newRegister = Context.NewRegisters.GetByKey(vm.Key);
                    if (newRegister != null)
                    {
                        var user = Context.Users.GetByMail(vm.MailAdress);
                        if (user != null)
                        {
                            Context.Groups.GetById(newRegister.GroupId).Users.Add(user);
                            Context.SaveChanges();
                        }
                    }

                    //Send register mail that explains wolfpack a bit
                    var ms      = new MailService();
                    var message = "<h2>Welcome to Wolfpack!</h2>" +
                                  "<p>Hello " + vm.FirstName + ",<br>" +
                                  "First of all welcome to Wolfpack!<br><br>" +
                                  "Wolfpack is a platform for people that want to create the most efficient teams possible based on an individual's skills. " +
                                  "In wolfpack most users will join groups where they are then added to events that will make the best possible teams. " +
                                  "To take part in a group you will first have to give yourself ratings about a few skills. With these rating we can properly create teams. " +
                                  "You can also start a group yourself, add people to this group and start events.<br><br>" +
                                  "With Wolfpack you can see a history of groups, events and teams you have partaken in. " +
                                  "You can see how others rated you about your skills and other useful information.<br><br>" +
                                  "We hope you'll enjoy using Wolfpack.<br>" +
                                  " - Wolfpack Team</p>";
                    ms.SendMailCustom(vm.MailAdress, "Wolfpack - Welcome to the pack", message, true);
                }
                else
                {
                    return(View("Register", vm));
                }

                return(RedirectToAction("Login", "Account", new { message = "Your account has been successfully created!" }));
            }
            else
            {
                ModelState.AddModelError("MailAdress", "This email is not valid please try again.");
                return(View("Register", vm));
            }
        }
        //đặt tour tự chọn
        public void DatTourTuChon(TourTuChonValidation validation)
        {
            var ks = _db.KhachSans.FirstOrDefault(n => n.ID == validation.ID);
            var kh = _db.Khachhangs.FirstOrDefault(k => k.Cmnd == validation.Cmnd);

            if (kh == null)
            {
                KhachhangViewModel khs = new KhachhangViewModel
                {
                    Hoten  = validation.Hoten,
                    Cmnd   = validation.Cmnd,
                    Diachi = validation.Diachi,
                    Sdt    = validation.Sdt,
                    Email  = validation.Email
                };
                var newKH = new Khachhang(khs);
                _db.Khachhangs.Add(newKH);
                _db.SaveChanges();
                HoadonViewModel hd = new HoadonViewModel
                {
                    Ngaylaphd   = DateTime.Now,
                    Ptthanhtoan = "Thanh toán online",
                    Tongtien    = validation.Tongtien,
                    Tinhtrang   = 0,
                    KhachhangID = newKH.ID
                };
                var newHD = new Hoadon(hd);
                _db.Hoadons.Add(newHD);
                _db.SaveChanges();
                CTHoadonTuChonViewModel cthd = new CTHoadonTuChonViewModel()
                {
                    Ngaynhan     = validation.Ngaynhan,
                    Ngaytra      = validation.Ngaytra,
                    Sophong      = validation.Sophong,
                    Sogiuongthem = validation.Sogiuongthem,
                    Sotreem      = validation.Sotreem,
                    Hoten        = validation.Hoten,
                    Sdt          = validation.Sdt,
                    Email        = validation.Email,
                    Ghichu       = validation.Ghichu,
                    Hoadoncode   = RandomString(),
                    KhachsanID   = ks.ID,
                    HoadonID     = newHD.ID
                };
                var newCTHD = new CTHoadonTuChon(cthd);
                _db.CTHoadonTuChons.Add(newCTHD);
                _db.SaveChanges();

                //send mail
                var webRoot    = _hostingEnvironment.WebRootPath;
                var body       = string.Empty;
                var pathToFile = _hostingEnvironment.WebRootPath
                                 + Path.DirectorySeparatorChar.ToString()
                                 + "templates"
                                 + Path.DirectorySeparatorChar.ToString()
                                 + "email"
                                 + Path.DirectorySeparatorChar.ToString()
                                 + "bookingtourtuchon.html";
                using (StreamReader reader = new StreamReader(pathToFile))
                {
                    body = reader.ReadToEnd();
                }
                body = body.Replace("{{hoadoncode}}", cthd.Hoadoncode);
                body = body.Replace("{{ngaylaphd}}", hd.Ngaylaphd.ToShortDateString());
                body = body.Replace("{{hoten}}", validation.Hoten);
                body = body.Replace("{{email}}", validation.Email);
                body = body.Replace("{{sogiuongthem}}", validation.Sogiuongthem.ToString());
                body = body.Replace("{{sdt}}", validation.Sdt);
                body = body.Replace("{{tinhtrang}}", "chưa thanh toán");
                body = body.Replace("{{ghichu}}", validation.Ghichu);
                body = body.Replace("{{tenks}}", ks.Tenks);
                body = body.Replace("{{diachi}}", ks.Diachi);
                body = body.Replace("{{ngaynhanphong}}", validation.Ngaynhan.ToShortDateString());
                body = body.Replace("{{ngaytraphong}}", validation.Ngaytra.ToShortDateString());
                body = body.Replace("{{loaiphong}}", ks.Loaiphong);
                body = body.Replace("{{sophong}}", validation.Sophong.ToString());
                body = body.Replace("{{gia}}", ks.Gia.ToString());
                body = body.Replace("{{giaphuthu}}", ks.Giaphuthu.ToString());
                body = body.Replace("{{sotreem}}", validation.Sotreem.ToString());
                body = body.Replace("{{giatreem}}", ks.Giatreem.ToString());
                body = body.Replace("{{tongtien}}", validation.Tongtien.ToString());
                var mailHelper = new MailHelpers();
                mailHelper.SendMail(validation.Email, "Thông tin booking tour tự chọn", body);
            }
            else
            {
                HoadonViewModel hd = new HoadonViewModel
                {
                    Ngaylaphd   = DateTime.Now,
                    Ptthanhtoan = "Thanh toán online",
                    Tongtien    = validation.Tongtien,
                    Tinhtrang   = 0,
                    KhachhangID = kh.ID
                };
                var newHD = new Hoadon(hd);
                _db.Hoadons.Add(newHD);
                _db.SaveChanges();
                CTHoadonTuChonViewModel cthd = new CTHoadonTuChonViewModel()
                {
                    Ngaynhan     = validation.Ngaynhan,
                    Ngaytra      = validation.Ngaytra,
                    Sophong      = validation.Sophong,
                    Sogiuongthem = validation.Sogiuongthem,
                    Sotreem      = validation.Sotreem,
                    Hoten        = validation.Hoten,
                    Sdt          = validation.Sdt,
                    Email        = validation.Email,
                    Ghichu       = validation.Ghichu,
                    Hoadoncode   = RandomString(),
                    KhachsanID   = ks.ID,
                    HoadonID     = newHD.ID
                };
                var newCTHD = new CTHoadonTuChon(cthd);
                _db.CTHoadonTuChons.Add(newCTHD);
                _db.SaveChanges();

                //send mail
                var webRoot    = _hostingEnvironment.WebRootPath;
                var body       = string.Empty;
                var pathToFile = _hostingEnvironment.WebRootPath
                                 + Path.DirectorySeparatorChar.ToString()
                                 + "templates"
                                 + Path.DirectorySeparatorChar.ToString()
                                 + "email"
                                 + Path.DirectorySeparatorChar.ToString()
                                 + "bookingtourtuchon.html";
                using (StreamReader reader = new StreamReader(pathToFile))
                {
                    body = reader.ReadToEnd();
                }
                body = body.Replace("{{hoadoncode}}", cthd.Hoadoncode);
                body = body.Replace("{{ngaylaphd}}", hd.Ngaylaphd.ToShortDateString());
                body = body.Replace("{{hoten}}", validation.Hoten);
                body = body.Replace("{{email}}", validation.Email);
                body = body.Replace("{{sogiuongthem}}", validation.Sogiuongthem.ToString());
                body = body.Replace("{{sdt}}", validation.Sdt);
                body = body.Replace("{{tinhtrang}}", "chưa thanh toán");
                body = body.Replace("{{ghichu}}", validation.Ghichu);
                body = body.Replace("{{tenks}}", ks.Tenks);
                body = body.Replace("{{diachi}}", ks.Diachi);
                body = body.Replace("{{ngaynhanphong}}", validation.Ngaynhan.ToShortDateString());
                body = body.Replace("{{ngaytraphong}}", validation.Ngaytra.ToShortDateString());
                body = body.Replace("{{loaiphong}}", ks.Loaiphong);
                body = body.Replace("{{sophong}}", validation.Sophong.ToString());
                body = body.Replace("{{gia}}", ks.Gia.ToString());
                body = body.Replace("{{giaphuthu}}", ks.Giaphuthu.ToString());
                body = body.Replace("{{sotreem}}", validation.Sotreem.ToString());
                body = body.Replace("{{giatreem}}", ks.Giatreem.ToString());
                body = body.Replace("{{tongtien}}", validation.Tongtien.ToString());
                var mailHelper = new MailHelpers();
                mailHelper.SendMail(validation.Email, "Thông tin booking tour tự chọn", body);
            }
        }
        public void DatTourMienTrung(DatTourValidation validation)
        {
            var tour = _db.Tours.FirstOrDefault(n => n.ID == validation.TourID);
            var kh   = _db.Khachhangs.FirstOrDefault(n => n.Cmnd == validation.Cmnd);

            if (kh == null)
            {
                var newKH = new Khachhang(validation);
                _db.Khachhangs.Add(newKH);
                _db.SaveChanges();

                //thêm thông tin tour miền Trung
                //thêm hóa đơn

                HoadonViewModel hd = new HoadonViewModel
                {
                    KhachhangID = newKH.ID,
                    Ngaylaphd   = DateTime.Now,
                    Ptthanhtoan = validation.Ptthanhtoan,
                    Tongtien    = validation.Tongtien,
                    Ghichu      = validation.Ghichu
                };
                var newHD = new Hoadon(hd);
                _db.Hoadons.Add(newHD);
                _db.SaveChanges();

                if (tour.Songuoi > 1)
                {
                    tour.Songuoi = tour.Songuoi - validation.Songuoidi;
                    _db.SaveChanges();
                }
                else
                {
                    tour.Songuoi   = tour.Songuoi - validation.Songuoidi;
                    tour.Trangthai = "hết chỗ";
                    _db.SaveChanges();
                }

                //thêm chi tiết hóa đơn

                CTHoadonTrungViewModel cthd = new CTHoadonTrungViewModel
                {
                    Hotenkhachhang = newKH.Hoten,
                    Sdt            = newKH.Sdt,
                    Email          = newKH.Email,
                    Hoadoncode     = RandomString(),
                    Songuoidi      = validation.Songuoidi,
                    HoadonID       = newHD.ID,
                    TourID         = tour.ID
                };
                var newCTHD = new CTHoadonTrung(cthd);
                _db.CTHoadonTrungs.Add(newCTHD);
                _db.SaveChanges();

                //send mail

                var webRoot    = _hostingEnvironment.WebRootPath;
                var body       = string.Empty;
                var pathToFile = _hostingEnvironment.WebRootPath
                                 + Path.DirectorySeparatorChar.ToString()
                                 + "templates"
                                 + Path.DirectorySeparatorChar.ToString()
                                 + "email"
                                 + Path.DirectorySeparatorChar.ToString()
                                 + "bookingdetail.html";
                using (StreamReader reader = new StreamReader(pathToFile))
                {
                    body = reader.ReadToEnd();
                }
                body = body.Replace("{{TourName}}", tour.Tentour);
                body = body.Replace("{{Code}}", tour.Code);
                body = body.Replace("{{Noixuatphat}}", tour.Diadiemkhoihanh);
                body = body.Replace("{{Diemden}}", tour.Diemden);
                body = body.Replace("{{Ngaydi}}", tour.Ngaydi.ToString());
                //body = body.Replace("{{Ngayve}}", tour.Ngayve.ToString());
                body = body.Replace("{{Sobooking}}", cthd.Hoadoncode);
                body = body.Replace("{{Tongtien}}", hd.Tongtien.ToString());
                body = body.Replace("{{Ngaydangky}}", hd.Ngaylaphd.ToString());
                body = body.Replace("{{Hinhthucthanhtoan}}", hd.Ptthanhtoan);
                body = body.Replace("{{Thoihanthanhtoan}}", "Vui lòng thanh toán trước khi tour khởi hành 3 ngày");
                body = body.Replace("{{Hoten}}", validation.Hoten);
                body = body.Replace("{{Diachi}}", validation.Diachi);
                body = body.Replace("{{Sdt}}", validation.Sdt);
                body = body.Replace("{{Email}}", validation.Email);
                body = body.Replace("{{Songuoidi}}", validation.Songuoidi.ToString());
                var mailHelper = new MailHelpers();
                mailHelper.SendMail(validation.Email, "Thông tin booking tour", body);
            }
            else
            {
                //thêm thông tin tour miền Trung
                //thêm hóa đơn

                HoadonViewModel hd = new HoadonViewModel
                {
                    KhachhangID = kh.ID,
                    Ngaylaphd   = DateTime.Now,
                    Ptthanhtoan = validation.Ptthanhtoan,
                    Tongtien    = validation.Tongtien,
                    Ghichu      = validation.Ghichu
                };
                var newHD = new Hoadon(hd);
                _db.Hoadons.Add(newHD);
                _db.SaveChanges();

                if (tour.Songuoi > 1)
                {
                    tour.Songuoi = tour.Songuoi - validation.Songuoidi;
                    _db.SaveChanges();
                }
                else
                {
                    tour.Songuoi   = tour.Songuoi - validation.Songuoidi;
                    tour.Trangthai = "hết chỗ";
                    _db.SaveChanges();
                }

                //thêm chi tiết hóa đơn

                CTHoadonTrungViewModel cthd = new CTHoadonTrungViewModel();
                cthd.Hotenkhachhang = kh.Hoten;
                cthd.Sdt            = kh.Sdt;
                cthd.Email          = kh.Email;
                cthd.Hoadoncode     = RandomString();
                cthd.Songuoidi      = validation.Songuoidi;
                cthd.HoadonID       = newHD.ID;
                cthd.TourID         = tour.ID;
                var newCTHD = new CTHoadonTrung(cthd);
                _db.CTHoadonTrungs.Add(newCTHD);
                _db.SaveChanges();

                //send mail

                var webRoot    = _hostingEnvironment.WebRootPath;
                var body       = string.Empty;
                var pathToFile = _hostingEnvironment.WebRootPath
                                 + Path.DirectorySeparatorChar.ToString()
                                 + "templates"
                                 + Path.DirectorySeparatorChar.ToString()
                                 + "email"
                                 + Path.DirectorySeparatorChar.ToString()
                                 + "bookingdetail.html";
                using (StreamReader reader = new StreamReader(pathToFile))
                {
                    body = reader.ReadToEnd();
                }
                body = body.Replace("{{TourName}}", tour.Tentour);
                body = body.Replace("{{Code}}", tour.Code);
                body = body.Replace("{{Noixuatphat}}", tour.Diadiemkhoihanh);
                body = body.Replace("{{Diemden}}", tour.Diemden);
                body = body.Replace("{{Ngaydi}}", tour.Ngaydi.ToString());
                //body = body.Replace("{{Ngayve}}", tour.Ngayve.ToString());
                body = body.Replace("{{Sobooking}}", cthd.Hoadoncode);
                body = body.Replace("{{Tongtien}}", hd.Tongtien.ToString());
                body = body.Replace("{{Ngaydangky}}", hd.Ngaylaphd.ToString());
                body = body.Replace("{{Hinhthucthanhtoan}}", hd.Ptthanhtoan);
                //int day = hd.Ngaylaphd.Date + 7;
                body = body.Replace("{{Thoihanthanhtoan}}", "N/A");
                body = body.Replace("{{Hoten}}", validation.Hoten);
                body = body.Replace("{{Diachi}}", validation.Diachi);
                body = body.Replace("{{Sdt}}", validation.Sdt);
                body = body.Replace("{{Email}}", validation.Email);
                body = body.Replace("{{Songuoidi}}", validation.Songuoidi.ToString());
                var mailHelper = new MailHelpers();
                mailHelper.SendMail(validation.Email, "Thông tin booking tour", body);
            }
        }
示例#10
0
        static void Main(string[] args)
        {
            if (args.Count() > 0)
            {
                if (args[0] == "ship")
                {
                    #region Mark As Shipped
                    try
                    {
                        //This is a fix for it being a desktop application.  This should not
                        //be run on a live webserver
                        ServicePointManager.ServerCertificateValidationCallback = delegate { return(true); };

                        //Use app.config so the directory can be changed regardless of the code
                        string dir = ConfigurationManager.AppSettings["ShippingData"].ToString();

                        //grab all the files in the directory
                        Directory.GetFiles(dir);
                        foreach (var file in Directory.GetFiles(dir))
                        {
                            //Get just the name of the file
                            FileInfo import   = new FileInfo(file);
                            string   filename = import.Name.Split('.')[0];

                            //Split on '_' and it should create a array with the length of 3
                            string[] filenamesplit = filename.Split('_');
                            if (filenamesplit.Length == 4)
                            {
                                string consumerKey    = filenamesplit[0];
                                string consumerSecret = filenamesplit[1];

                                var client = new RestClient();
                                client.BaseUrl       = APIHelper.GetBaseUri();
                                client.Authenticator = new HttpBasicAuthenticator(consumerKey, consumerSecret);

                                var summaries = ImportHelper.ImportShippingSummaries(file);


                                if (summaries.FirstOrDefault() != null && summaries.FirstOrDefault().Company_ID != "-1")
                                {
                                    //changed to false if any of the orders fail to be posted.
                                    bool allShipped = true;
                                    foreach (var summary in summaries)
                                    {
                                        //Use the summary information to create a JSON object
                                        string order = OrderServices.GetOrderByOrderNumber(client, summary);

                                        //if the string did not return and error try to
                                        //do a post.
                                        if (!order.StartsWith("An Error Has Occured"))
                                        {
                                            //Shipsation async code, but it causes business logic problems
                                            //Task tsk = OrderServices.MakeAsyncOrderPost(order, consumerKey, consumerSecret);
                                            //tsk.Wait();

                                            //Post the order to be marked.
                                            allShipped = OrderServices.MarkOrderPost(client, order);
                                        }
                                        else
                                        {
                                            allShipped = false;
                                        }
                                    }

                                    if (allShipped)
                                    {
                                        // File.Delete(file);
                                        //Update first row companyID to -1
                                        string DSN = string.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=Excel 8.0", file);
                                        using (System.Data.OleDb.OleDbConnection Con = new System.Data.OleDb.OleDbConnection(DSN))
                                        {
                                            Con.Open();
                                            using (System.Data.OleDb.OleDbCommand Com = new System.Data.OleDb.OleDbCommand())
                                            {
                                                Com.Connection  = Con;
                                                Com.CommandText = "UPDATE [Shipping_Summary___Optional_Sav$] SET [Company_ID] = -1 WHERE [Company_ID] = " + summaries.FirstOrDefault().Company_ID;
                                                Com.ExecuteNonQuery();
                                            }
                                            Con.Close();
                                        }
                                    }
                                    else
                                    {
                                        MailMessage mail       = new MailMessage();
                                        SmtpClient  SmtpServer = new SmtpClient("smtp.gmail.com");

                                        mail.From = new MailAddress("*****@*****.**");
                                        mail.To.Add("*****@*****.**");
                                        mail.Subject = "An Error Has Occured Posting to Ship Station";
                                        mail.Body    = string.Format("Not all orders for the file {0} were marked as shipped", import.Name);

                                        SmtpServer.Port        = 587;
                                        SmtpServer.Credentials = new NetworkCredential("*****@*****.**", "5HB7c9ut");
                                        SmtpServer.EnableSsl   = true;

                                        SmtpServer.Send(mail);
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        MailMessage mail       = new MailMessage();
                        SmtpClient  SmtpServer = new SmtpClient("smtp.gmail.com");

                        mail.From = new MailAddress("*****@*****.**");
                        mail.To.Add("*****@*****.**");
                        mail.Subject = "An Error Has Occured Posting to Ship Station";
                        mail.Body    = string.Format(ex.ToString());

                        SmtpServer.Port        = 587;
                        SmtpServer.Credentials = new System.Net.NetworkCredential("*****@*****.**", "5HB7c9ut");
                        SmtpServer.EnableSsl   = true;

                        SmtpServer.Send(mail);
                    }
                    #endregion
                }

                if (args[0] == "orders")
                {
                    #region Pull Order
                    var customers = ImportHelper.ImportShipstationCustomers();
                    foreach (var customer in customers)
                    {
                        Console.WriteLine("Processing {0}", customer.CompanyName);
                        var client = new RestClient();
                        client.BaseUrl       = APIHelper.GetBaseUri();
                        client.Authenticator = new HttpBasicAuthenticator(customer.Key, customer.Token);


                        //RestRequest request = new RestRequest("users", Method.GET);
                        //IRestResponse response = client.Execute(request);
                        //get all the stores
                        Console.WriteLine("Getting All Stores");
                        List <Store> stores = StoreService.GetAllStores(client);

                        Console.WriteLine("Pulling down unshipped orders");
                        //var orders = OrderServices.GetOrders(client, storeId);
                        List <Order> orders = new List <Order>();
                        foreach (var store in stores)
                        {
                            Console.WriteLine("Pulling down unshipped orders for {0}", store.storeName);
                            orders.AddRange(OrderServices.GetOrders(client, store.storeId));
                        }


                        var SClientorders = orders.Where(o => o.userId == APIHelper.GetShipstationUserID()).ToList();

                        //check to see if the id's have been
                        List <string> extractedids = new List <string>();
                        using (StreamReader reader = new StreamReader(System.Configuration.ConfigurationManager.AppSettings["Path"] + "extractedids.txt"))
                        {
                            string line = reader.ReadLine();
                            while (line != null)
                            {
                                extractedids.Add(line.Trim());
                                line = reader.ReadLine();
                            }

                            reader.Close();
                        }
                        foreach (var id in extractedids)
                        {
                            var order = SClientorders.Where(xo => xo.orderNumber == id).FirstOrDefault();
                            if (order != null)
                            {
                                SClientorders.Remove(order);
                            }
                        }


                        if (SClientorders.Count > 0)
                        {
                            Console.WriteLine("Creating Extraction Report Count : {0}", SClientorders.Count);
                            ExportHelpers.ExtractionReport(SClientorders, customer, stores);

                            Console.WriteLine("Sending Email");
                            MailHelpers.SendEmailWithOrders(customer.CompanyName);
                            Console.WriteLine("Finished Processing {0}", customer.CompanyName);

                            //save the id's
                            using (StreamWriter writer = new StreamWriter(System.Configuration.ConfigurationManager.AppSettings["Path"] + "extractedids.txt", true))
                            {
                                foreach (var order in SClientorders.OrderBy(y => y.orderNumber))
                                {
                                    writer.WriteLine(order.orderNumber);
                                }
                            }
                        }
                        else
                        {
                            MailMessage mail       = new MailMessage();
                            SmtpClient  SmtpServer = new SmtpClient("smtp.gmail.com");

                            mail.From = new MailAddress("*****@*****.**");
                            mail.To.Add("[email protected],[email protected]");
                            mail.Bcc.Add("*****@*****.**");
                            mail.Subject = customer.CompanyName + " Orders From Ship Station - No New Orders";
                            mail.Body    = string.Format("No New Orders");

                            SmtpServer.Port        = 587;
                            SmtpServer.Credentials = new System.Net.NetworkCredential("*****@*****.**", "5HB7c9ut");
                            SmtpServer.EnableSsl   = true;

                            SmtpServer.Send(mail);
                        }
                    }
                    #endregion
                }
                Console.WriteLine("done");
            }
            else
            {
                MailMessage mail       = new MailMessage();
                SmtpClient  SmtpServer = new SmtpClient("smtp.gmail.com");

                mail.From = new MailAddress("*****@*****.**");
                mail.To.Add("*****@*****.**");
                mail.Subject = "An Error Has Occured Posting to Ship Station";
                mail.Body    = string.Format("No Argument Has Been Passed");

                SmtpServer.Port        = 587;
                SmtpServer.Credentials = new System.Net.NetworkCredential("*****@*****.**", "5HB7c9ut");
                SmtpServer.EnableSsl   = true;

                SmtpServer.Send(mail);
            }
        }
示例#11
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());
        }
示例#12
0
        public ActionResult AddUser(AddUserVM vm)
        {
            string input = vm.UserName;

            var user = Context.Users.FirstOrDefault(g => g.UserName == vm.UserName || g.Mail == vm.UserName);

            //Return a list with possible users if the username is not found.
            if (user == null)
            {
                if (MailHelpers.CheckIfValidEmail(vm.UserName))
                {
                    string key     = Guid.NewGuid().ToString();
                    string baseUrl = Request.Url.Scheme + "://" + Request.Url.Authority + Request.ApplicationPath.TrimEnd('/') + "/";
                    string link    = baseUrl + "Account/Register?key=" + key;
                    Context.NewRegisters.Add(new NewRegister
                    {
                        Key     = key,
                        Email   = vm.UserName,
                        GroupId = vm.GroupId
                    });
                    Context.SaveChanges();
                    MailService ms = new MailService();
                    ms.SendRegisterMail(vm.UserName, link);

                    return(View(new AddUserVM {
                        GroupId = vm.GroupId, Message = "An email has been sent to the given email."
                    }));
                }

                var possibleUsers = Context.Users.Select(g => new Web.Models.Group.UserVM
                {
                    Id        = g.Id,
                    UserName  = g.UserName,
                    FirstName = g.FirstName,
                    LastName  = g.LastName
                }).Where(g => g.UserName.Contains(vm.UserName)).ToList();

                if (possibleUsers != null && possibleUsers.Count > 0)
                {
                    return(View(new AddUserVM {
                        GroupId = vm.GroupId, PossibleUsers = possibleUsers
                    }));
                }
                else
                {
                    return(RedirectToAction("Details", new { id = vm.Id, state = "No user" }));
                }
            }
            else
            {
                var group = Context.Groups.GetById(vm.Id);
                if (!group.Archived)
                {
                    if (group.Users == null)
                    {
                        group.Users = new List <User>();
                    }
                    group.Users.Add(user);

                    user.Notifications.Add(new Notification
                    {
                        Title   = "Added to group: " + group.GroupName,
                        Content = $"You've been added to the group '{group.GroupName}' " +
                                  $"and can now rate yourself for the associated skills through the following link: " +
                                  Url.Action("RateUser", "Group", new { userId = user.Id }, this.Request.Url.Scheme),
                        Date   = DateTime.Now,
                        IsRead = false
                    });

                    Context.SaveChanges();

                    return(RedirectToAction("Details", new { id = vm.Id, state = "success" }));
                }
                else
                {
                    var message = "Target group is archived";
                    return(RedirectToAction("Index", message));
                }
            }
        }
示例#13
0
        public void CheckIfValidMail_Mail_IsFalse()
        {
            var validMail = MailHelpers.CheckIfValidEmail("wolfpack.nhlstenden@gmail");

            Assert.IsFalse(validMail);
        }