示例#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 <HttpStatusCode> PostQuestionToVendor(int id, [FromBody] EmailMessage emailMsg)
        {
            Vendor vendor = await _vendorQuery.GetById(id);

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

            emailMsg.personalizations[0].to[0].email = vendor.userName;
            return(await _emailQuery.sendEmailViaPostAsync(emailMsg));
        }
示例#3
0
        public async Task <IActionResult> GetFavoriteVendors(string userName)
        {
            List <Vendor> favoriteVendors = new List <Vendor>();

            try
            {
                var result = await _favoritesQuery.GetAllByUserName(userName);

                // Does not include empty results
                if (result == null)
                {
                    return(new NotFoundResult());
                }

                foreach (Favorite fav in result)
                {
                    var vendor = await _vendorsQuery.GetById(fav.vendorId);

                    if (vendor != null)
                    {
                        favoriteVendors.Add(vendor);
                    }
                }

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

                return(new BadRequestResult());
            }
        }
示例#4
0
        public async Task <IActionResult> GetById(int id)
        {
            try
            {
                var vendor = await _vendorQuery.GetById(id);

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

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

                return(new BadRequestResult());
            }
        }