예제 #1
0
        public async Task <IActionResult> GetById(int id)
        {
            try
            {
                Reservation reservation = await _reservationsQuery.GetById(id);

                if (reservation == null)
                {
                    return(new NotFoundResult());
                }

                return(new OkObjectResult(reservation));
            }
            catch (Exception ex)
            {
                await _logger.LogError(HttpContext.User, ex);

                return(new BadRequestResult());
            }
        }
예제 #2
0
        public async Task <HttpStatusCode> PostReservationToVendor(int reservationId, [FromBody] EmailMessage emailMsg)
        {
            // retrieve reservation via reservationId
            Reservation reservation = await _reservationQuery.GetById(reservationId);

            // check if reservation is returned
            if (reservation == null)
            {
                return(HttpStatusCode.NotFound);
            }

            int    vendorId = reservation.vendorId ?? default(int);
            Vendor vendor   = await _vendorQuery.GetById(vendorId);

            if (vendor == null)
            {
                return(HttpStatusCode.NotFound);
            }

            int            vendorServiceId = reservation.vendorServiceId ?? default(int);
            VendorServices vendorService   = await _vendorServiceQuery.GetById(vendorServiceId);

            if (vendorService == null)
            {
                return(HttpStatusCode.NotFound);
            }

            Boolean isSuccessful = true;

            // create to list and set
            List <EmailPersonalization> personalizations = new List <EmailPersonalization>();
            List <EmailRecipient>       emailTos         = new List <EmailRecipient>();
            List <EmailContent>         emailContents    = new List <EmailContent>();
            EmailPersonalization        personalization  = new EmailPersonalization();

            emailTos.Add(new EmailRecipient(vendor.name, vendor.userName));
            personalization.to = emailTos;
            personalizations.Add(personalization);
            emailMsg.personalizations = personalizations;

            // Update Content
            String hostname = _emailQuery.getBaseUrlForEmail(HttpContext);

            EmailContent emailContent = new EmailContent();

            emailContent.type = "text/html";

            StringBuilder htmlBuilder = new StringBuilder();

            htmlBuilder.AppendLine("<div>").Append("Hello, ").Append(vendor.name).Append(". You have a requested reservation for the ");
            htmlBuilder.Append(vendorService.serviceName).Append(" waiting for you via Occasions.</div>");
            htmlBuilder.AppendLine("Please click ").Append("<a href='").Append(hostname).Append("/reservations-vendor'>here</a>").Append(" to view it.");
            emailContent.value = htmlBuilder.ToString();
            Console.WriteLine(htmlBuilder.ToString());
            emailContents.Add(emailContent);
            emailMsg.content = emailContents;

            Task <HttpStatusCode> response = _emailQuery.sendEmailViaPostAsync(emailMsg);

            if (response.Result.Equals(HttpStatusCode.Accepted))
            {
                Console.WriteLine("Successfully sent email to " + vendor.userName);
            }
            else
            {
                isSuccessful = false;
                Console.WriteLine("Error sending email to " + vendor.userName);
            }

            if (isSuccessful)
            {
                return(HttpStatusCode.Accepted);
            }
            else
            {
                return(HttpStatusCode.BadRequest);
            }
        }