public static DrawSubmissionListingDto ToDto(this DrawSubmission self, bool includeSerial = false)
 {
     return(new DrawSubmissionListingDto()
     {
         Id = self.Id,
         EmailAddress = self.EmailAddress.Value,
         FirstName = self.FirstName,
         LastName = self.LastName,
         SerialNumber = includeSerial ? self.SerialNumber.Serial : string.Empty,
         SubmissionTimeUtc = self.SubmissionTimeUtc
     });
 }
        public async Task <DrawSubmission> Submit(string firstName, string lastname, EmailAddress emailAddress, SerialNumber serialNumber)
        {
            if (serialNumber == null)
            {
                throw new ArgumentNullException(nameof(serialNumber));
            }

            serialNumber.Use();

            var submission = new DrawSubmission(
                firstName: firstName,
                lastName: lastname,
                emailAddress: emailAddress,
                serialNumber: serialNumber);
            await _dbContext.DrawSubmissions.AddAsync(submission);

            eventPublisher.Publish(new DrawSubmissionRetrievedDomainEvent(submission.Id, emailAddress.Value));

            return(submission);
        }
        public IActionResult Create(DrawSubmission drawSubmission)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            if (!drawSubmission.IsEighteen)
            {
                return(RedirectToAction("NotEighteen"));
            }

            if (!IsUsedTwice(drawSubmission.SerialNumber))
            {
                return(View());
            }

            if (!IsValid(drawSubmission.SerialNumber))
            {
                return(View());
            }

            if (IsWinner())
            {
                drawSubmission.IsWinner = true;
                db.DrawSubmissions.Add(drawSubmission);
                db.SaveChanges();

                return(RedirectToAction("Winner"));
            }
            else
            {
                drawSubmission.IsWinner = false;
                db.DrawSubmissions.Add(drawSubmission);
                db.SaveChanges();

                return(RedirectToAction("Loser"));
            }
        }