コード例 #1
0
        /// <summary>
        /// Inserts a new reservation
        /// </summary>
        /// <param name="reservation">Reservation</param>
        /// <returns>Saved reservation</returns>
        public async Task <Reservation> Insert(Reservation reservation)
        {
            try
            {
                using (var db = _database)
                {
                    var connection = db.Connection as MySqlConnection;
                    await connection.OpenAsync();

                    string query = @"INSERT INTO occasions.reservations(userName, eventId, vendorId, vendorServiceId, status, numberReserved, active) "
                                   + @"VALUES(@userName, @eventId, @vendorId, @vendorServiceId, 'New', @numberReserved, 1); "
                                   + @"SELECT * FROM occasions.reservations WHERE id = LAST_INSERT_ID() AND active = 1;";

                    var reserved = (await connection.QueryAsync <Reservation>(query, reservation)).FirstOrDefault();
                    if (reserved != null)
                    {
                        reserved.evt = await _eventQuery.GetEventByGuid(reserved.eventId);

                        reserved.vendor = await _vendorsQuery.GetById(reserved.vendorId.Value);

                        reserved.vendorService = await _vendorServicesQuery.GetById(reserved.vendorServiceId.Value);
                    }

                    return(reserved);
                }
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
コード例 #2
0
        public async Task <IActionResult> GetServiceById(int id)
        {
            try
            {
                VendorServices service = await _vendorServicesQuery.GetById(id);

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

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

                return(new BadRequestResult());
            }
        }
コード例 #3
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);
            }
        }