示例#1
0
        public DbError AddTournament(TournamentModel tournament)
        {
            //TournamentModel _tournament = new TournamentModel();
            try
            {
                TournamentInviteModel invite = new TournamentInviteModel()
                {
                    DateCreated          = DateTime.Now,
                    IsExpired            = false,
                    NumberOfUses         = 0,
                    TournamentID         = tournament.TournamentID,
                    TournamentInviteCode = tournament.InviteCode
                };


                //_tournament = tournament;
                //_tournament.CreatedOn = DateTime.Now;
                //_tournament.LastEditedOn = DateTime.Now;
                ////context.SaveChanges();
                //context.TournamentModels.Add(_tournament);
                context.TournamentModels.Add(tournament);
            }
            catch (Exception ex)
            {
                exception = ex;
                WriteException(ex);
                return(DbError.FAILED_TO_ADD);
            }
            return(DbError.SUCCESS);
        }
示例#2
0
        public bool SendTournamentInviteEmail(TournamentInviteModel invite, string url, List <string> recepiantEmails)
        {
            try
            {
                var msg = new SendGridMessage();

                AccountModel sender = unitOfWork.AccountRepo.Get(invite.Tournament.CreatedByID);
                msg.SetFrom(new EmailAddress(sender.Email, sender.GetFullName()));
                var templateId = "d921bc44-497d-41b4-a670-56f4af8f37a5";
                msg.TemplateId = templateId;


                Dictionary <string, string> substitutions = new Dictionary <string, string>()
                {
                    { "{sender_name}", sender.GetFullName().ToString() },
                    { "{account_creation_url}", "http://localhost:20346/Account/Register" },
                    { "{tournament_title}", invite.Tournament.Title },
                    { "{game_type}", invite.Tournament.GameType.Title },
                    { "{platform}", invite.Tournament.Platform.PlatformName },
                    { "{registration_start_date}", invite.Tournament.RegistrationStartDate.ToShortDateString() },
                    { "{registration_end_date}", invite.Tournament.RegistrationEndDate.ToShortDateString() },
                    { "{tournament_start_date}", invite.Tournament.TournamentStartDate.ToShortDateString() },
                    { "{tournament_url}", url }
                };
                msg.AddSubstitutions(substitutions);

                var recepiants = new List <EmailAddress>();
                foreach (var recepiant in recepiantEmails)
                {
                    recepiants.Add(new EmailAddress(recepiant));
                }
                msg.AddTos(recepiants);


                Execute(client, msg).Wait();
            }
            catch (Exception ex)
            {
                unitOfWork.SetException(ex);
                return(false);
            }
            return(true);
        }