コード例 #1
0
        /// <summary>
        /// Create ticket for company registration
        /// </summary>
        /// <param name="company">Company</param>
        /// <param name="group">Group</param>
        /// <param name="email">Email</param>
        /// <param name="firstName">First Name</param>
        /// <param name="secondName">Second Name</param>
        /// <returns>Generated ticket</returns>
        public string CreateTicketForCompany(Company company, BBWT.Data.Membership.Group group, string email = null, string firstName = null, string secondName = null)
        {
            if (company == null && group == null)
            {
                throw new ArgumentException("No company or group ID selected");
            }

            string ticket;

            do
            {
                ticket = Guid.NewGuid().ToString();
            }while (this.context.CompanySecurityTickets.Any(entry => entry.Ticket == ticket));

            this.context.CompanySecurityTickets.Add(new CompanySecurityTicket
            {
                Ticket     = ticket,
                ExpiredOn  = DateTime.Now.AddDays(TicketExpiredIn),
                Company    = company,
                Group      = group,
                Email      = email,
                FirstName  = firstName,
                SecondName = secondName
            });

            this.context.Commit();
            return(ticket);
        }
コード例 #2
0
        /// <summary>
        /// Check company group
        /// </summary>
        /// <param name="ticket">ticket value</param>
        /// <param name="group">group</param>
        /// <returns>company ticket</returns>
        public CompanySecurityTicket CheckTicketForCompanyGroup(string ticket, BBWT.Data.Membership.Group group)
        {
            Guid ticketGuid;

            if (!Guid.TryParse(ticket, out ticketGuid))
            {
                throw new ArgumentException("Ticket is not a valid Guid", "ticket");
            }

            if (group == null)
            {
                throw new ArgumentNullException("group", "Group should not be null");
            }

            return(this.context.CompanySecurityTickets.FirstOrDefault(entry => entry.Ticket == ticket &&
                                                                      entry.Group == group && entry.ExpiredOn >= DateTime.Now && !entry.IsUsed));
        }