Example #1
0
        public IHttpActionResult ResignOffer(ReserveOfferDto dto)
        {
            using (var context = _provider.GetNewContext())
            {
                using (var transaction = new TransactionScope())
                {
                    Offer offer    = context.Offers.FirstOrDefault(o => o.Id == dto.OfferId);
                    User  customer = context.Users.FirstOrDefault(u => u.Username.Equals(dto.Username));
                    User  vendor   = context.Users.FirstOrDefault(x => x.Id == offer.VendorId);

                    if (offer == null || customer == null)
                    {
                        return(NotFound());
                    }
                    if (!offer.IsBooked)
                    {
                        return(BadRequest());
                    }


                    OfferInfo offerInfo    = context.OfferInfo.FirstOrDefault(o => o.Id == offer.OfferInfoId);
                    UserData  customerData = context.UserData.FirstOrDefault(x => x.Id == customer.UserDataId);
                    UserData  vendorData   = context.UserData.FirstOrDefault(x => x.Id == vendor.UserDataId);
                    Room      room         = context.Rooms.FirstOrDefault(x => x.Id == offer.RoomId);
                    Place     place        = context.Places.FirstOrDefault(x => x.Id == room.PlaceId);
                    offer.IsBooked = false;
                    offer.Customer = null;
                    context.SaveChanges();
                    //Wysłanie powiadomienia mailowego, ostatni parametr oznacza rezygnację
                    EmailNotification.SendNotification(offerInfo, place, vendorData, customerData, room, false);
                    transaction.Complete();
                }
            }
            return(Ok(true));
        }
        /// <summary>
        /// Wysyła zapytanie o rezygnację z zarezerwowanej oferty
        /// </summary>
        /// <param name="username"></param>
        /// <param name="offerId"></param>
        /// <returns></returns>
        public async Task ResignOffer(string username, int offerId)
        {
            ReserveOfferDto dto = new ReserveOfferDto()
            {
                Username = username,
                OfferId  = offerId
            };

            await Post <ReserveOfferDto, bool>("resign", dto);
        }
Example #3
0
        public void ResignOfferTest()
        {
            ReserveOfferDto dto = new ReserveOfferDto()
            {
                Username = "******",
                OfferId  = 3
            };

            IHttpActionResult result = _controller.ResignOffer(dto);
            var contentResult        = result as OkNegotiatedContentResult <bool>;

            Offer o = _context.Offers.FirstOrDefault(x => x.Id == dto.OfferId);

            Assert.IsNotNull(o);
            Assert.AreEqual(o.IsBooked, false);
            Assert.IsNull(o.Customer);
        }