public IActionResult GetUserHostOffers()
        {
            string userId = GetUserId();

            if (userId == "error")
            {
                return(Unauthorized());
            }
            var hostOffers = _hostOfferService.GetMultiByCondition(s => s.Receiver.Id == userId && s.IsDeleted != true && s.IsCanceled != true, new string[] { "Sender" });

            return(Ok(hostOffers));
        }
Exemple #2
0
        public IActionResult PostHostOffer(HostOffer hostOffer, string id)
        {
            string userId;

            try
            {
                userId = User.Claims.First(c => c.Type == "UserID").Value;
            }
            catch
            {
                return(Unauthorized());
            }
            hostOffer.CreateDate = DateTime.Now;
            var traveler = _userService.GetSingleByCondition(s => s.Id == id, null);
            var host     = _userService.GetSingleByCondition(s => s.Id == userId, null);

            if (host == null || traveler == null)
            {
                return(NotFound());
            }
            var oldHostOffers = _hostOfferService.GetMultiByCondition(s => s.Sender.Id == host.Id && s.Receiver.Id == traveler.Id, null);

            foreach (HostOffer i in oldHostOffers)
            {
                if (i.IsAccepted != true && i.IsCanceled != true)
                {
                    return(BadRequest(new { message = "You already have unaccepted hostoffer with this user!" }));
                }
            }
            hostOffer.Receiver = traveler;
            hostOffer.Sender   = host;
            _hostOfferService.Add(hostOffer);
            _hostOfferService.SaveChanges();
            return(Ok());
        }