Esempio n. 1
0
        public void SendEmailWithHouseRanking(string ranking)
        {
            string      emailSubject = string.Format(EMAIL_SUBJECT, ranking);
            EmailServer emailServer  = new EmailServer(this._emailAddresses, null, emailSubject);

            emailServer.SendEmail();
        }
Esempio n. 2
0
        /// <summary>进行用户重置密码操作的处理
        /// </summary>
        /// <returns>返回重置密码操作的结果</returns>
        public ActionResult ResetPwd()
        {
            string email = Request["email"];
            string pwd   = EncryptUtil.GenerateRandomPassword();

            string content = string.Format("您的新密码是:{0}, 请登录网站{1}修改你的密码", pwd, "http://xxx/");

            EmailServer.SendEmail(email, "", content);
            return(Content("邮件已经发送,请查收"));
        }
Esempio n. 3
0
        public async Task <IActionResult> OnPostInvite()
        {
            Couple = await GetAuthorizedCouple();

            if (Couple == null)
            {
                return(NotFound());
            }

            if (!ModelState.IsValid(nameof(Invite)))
            {
                return(Page());
            }

            Invite.EmailAddress = Invite.EmailAddress.ToLower();

            // Load the dinner itself, including other couples
            await Database.GetDinnerAsync(Couple.Dinner.ID);

            foreach (Couple storedCouple in Couple.Dinner.Couples)
            {
                if (storedCouple.EmailAddress == Invite.EmailAddress)
                {
                    ModelState.AddModelError(nameof(Invite), $"{ Invite.Person } met emailadres { Invite.EmailAddress } is al uitgenodigd.");
                    return(Page());
                }
            }

            // Invite
            Couple invitedCouple = await Database.CreateCoupleAsync(Couple.Dinner.ID, Invite.EmailAddress, Invite.Person);

            if (invitedCouple == null)
            {
                ModelState.AddModelError(nameof(Invite), $"Kan { Invite.Person } nu niet uitnodigen.");
                return(Page());
            }

            EmailServer.SendEmail(invitedCouple.EmailAddress, "Uitnodiging",
                                  $"U ben uitgenodigd door { Couple.PersonMain } om deel te namen aan een WalkingDinner. Bekijk uit uitnodiging <a href=\"{ ModelPath.GetAbsolutePathWithAuthorization<Couples.SeeInvitationModel>( Request.Host, invitedCouple.ID, invitedCouple.AdminCode ) }\">Hier</a>");

            ViewData["InviteResult"] = $"{ Invite.Person } is uitgenodigd.";

            // Clear input data
            ModelState.Clear(nameof(Invite));
            Invite = null;

            return(Page());
        }
Esempio n. 4
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            // Strip seconds
            Dinner.Date             = Dinner.Date.SetTime(Dinner.Date.Hour, Dinner.Date.Minute, 0, 0);
            Dinner.SubscriptionStop = Dinner.SubscriptionStop.SetTime(Dinner.Date.Hour, Dinner.Date.Minute, 0, 0);

            // Dont allow negative prices
            Dinner.Price = Math.Max(Dinner.Price, 0.0);

            if (Dinner.Date < DateTime.Now.AddDays(Dinner.MIN_DAYS_IN_ADVANCE).SetTime(0, 0))
            {
                ModelState.AddModelError("Dinner.Date", $"Kies een datum minimaal { Dinner.MIN_DAYS_IN_ADVANCE } dagen in de toekomst.");
                return(Page());
            }

            if ((Dinner.Date - Dinner.SubscriptionStop).TotalHours < 24)
            {
                ModelState.AddModelError("Dinner.SubscriptionStop", "Kies een tijd minimaal 24 uur vσσr het diner.");
                return(Page());
            }

            if (Dinner.HasPrice && (string.IsNullOrWhiteSpace(Couple.IBAN)))
            {
                ModelState.AddModelError("Couple.IBAN", "Een bankrekening is verplicht als het evenement geld kost.");
                return(Page());
            }

            if (await Database.CreateDinnerAsync(Dinner, Couple) == null)
            {
                ModelState.AddModelError(nameof(Dinner), "Kan dinner nu niet aanmaken.");
                return(Page());
            }

            EmailServer.SendEmail(Couple.EmailAddress, "Nieuw dinner",
                                  $"Nieuw diner aangemaakt, code: <a href=\"{ ModelPath.GetAbsolutePathWithAuthorization<Management.EditDinnerModel>( Request.Host, Couple.ID, Couple.AdminCode )}\">Beheer</a>");

            return(Redirect(ModelPath.Get <AwaitEmailModel>()));
        }
Esempio n. 5
0
        static void EmailServerTest()
        {
            EmailServer email = new EmailServer("*****@*****.**", "*****@*****.**", "Test", "This is a test.");

            email.SendEmail();
        }
Esempio n. 6
0
        public async Task <IActionResult> OnPostAsync()
        {
            var getResult = await GetCoupleAsync();

            if (getResult != null)
            {
                return(getResult);
            }

            Couple[] allCouples = (await Database.GetCouplesAsync(Couple.Dinner.ID)).ToArray();
            if (Couple.Dinner.HasPrice)
            {
                allCouples = allCouples.Where(o => o.HasPayed).ToArray();
            }
            CoupleCount = allCouples.Length;

            if (!ModelState.IsValid)
            {
                return(Page());
            }

            int courseCount = 0;

            foreach (var entry in CourseSelection)
            {
                if (!entry.Value)
                {
                    continue;
                }

                courseCount++;
            }

            if (courseCount < 2)
            {
                ModelState.AddModelError("CourseSelection", "Kies minimaal 2 gangen!");
                return(Page());
            }

            int couplesPerGroup   = courseCount;
            int parallelMealCount = CoupleCount / couplesPerGroup;

            // Rounding errors:
            CoupleCount = parallelMealCount * couplesPerGroup;
            Schema schema = Schema.GenerateSchema(allCouples, courseCount);

            if ((schema == null) || !Schema.ValidSchema(schema, allCouples, CoupleCount))
            {
                // ERROR

                ViewData["Schema-error"] = "Huidige indeling is niet mogelijk.";
                return(Page());
            }

            // Add the remaing couples
            int remainingCoupleCount = allCouples.Length - CoupleCount;

            if (remainingCoupleCount > 0)
            {
                Couple[] remainingCouples = new Couple[parallelMealCount];
                Array.Copy(allCouples, allCouples.Length - remainingCoupleCount, remainingCouples, 0, remainingCoupleCount);

                foreach (Course course in schema.Courses)
                {
                    for (int i = 0; i < parallelMealCount; i++)
                    {
                        course.Meals[i].Couples[course.Meals[i].Couples.Length - 1] = remainingCouples[i];
                    }

                    // Inverse shift
                    var temp = remainingCouples[0];
                    for (int i = 1; i < remainingCouples.Length; i++)
                    {
                        remainingCouples[i - 1] = remainingCouples[i];
                    }

                    remainingCouples[remainingCouples.Length - 1] = temp;
                }
            }

            // Send emails
            for (int i = 0; i < schema.Courses.Length; i++)
            {
                foreach (Meal meal in schema.Courses[i].Meals)
                {
                    Couple chef = meal.Couples[i];

                    StringBuilder emailBody = new StringBuilder();

                    emailBody.Append($"Hoi { chef.PersonMain.FirstName }");
                    if (chef.PersonGuest != null)
                    {
                        emailBody.Append($" en { chef.PersonGuest.FirstName }");
                    }
                    emailBody.AppendLine(",");

                    int count = 0;
                    foreach (Couple couple in meal.Couples)
                    {
                        if (couple == null)
                        {
                            continue;
                        }

                        count++;
                        if (couple.PersonGuest != null)
                        {
                            count++;
                        }
                    }

                    emailBody.AppendLine($"Jij/jullie gaan koken in ronde { i + 1 }! Jullie maken een '{ CourseSelection.Keys.ElementAt( i ) }' voor { count } mensen (inclusief jezelf).");
                    emailBody.AppendLine("De volgende dieetwensen zijn opgegeven:");

                    bool hasGuidelines = false;
                    foreach (Couple couple in meal.Couples)
                    {
                        if (couple == null)
                        {
                            continue;
                        }

                        if (couple == chef)
                        {
                            continue;
                        }

                        string guidelines = couple.DietaryGuidelines?.Trim();
                        if (!string.IsNullOrEmpty(guidelines))
                        {
                            emailBody.AppendLine(guidelines);
                            hasGuidelines = true;
                        }
                    }

                    if (!hasGuidelines)
                    {
                        emailBody.AppendLine("Geen.");
                    }

                    emailBody.AppendLine("Veel plezier!");

                    EmailServer.SendEmail(chef.EmailAddress, "Walking dinner!", emailBody.ToString());
                }
            }

            List <Route> routes = new List <Route>();

            foreach (Couple couple in allCouples)
            {
                for (int i = 0; i < schema.Courses.Length; i++)
                {
                    Meal   meal = schema.Courses[i].GetMealForCouple(couple);
                    Couple chef = meal.Couples[i];

                    routes.Add(new Route(couple, chef, i));
                }
            }

            byte[] pdf = Letter.Generate(routes, courseCount, Couple.Dinner.Date);

            return(File(pdf, System.Net.Mime.MediaTypeNames.Application.Pdf, "schema.pdf"));

            //ViewData[ "message" ] = "Schema is opgeslagen.";
            //return Page();
        }