Пример #1
0
        public async Task <IActionResult> Rent(int id, DateTime rentFrom, DateTime rentTo)
        {
            var Add = _context.Advertise.Include(a => a.RentRanges).First(async => async.ID == id);

            if (rentFrom == DateTime.MinValue || rentTo == DateTime.MinValue)
            {
                return(RedirectToAction(nameof(Details), new { id = id }));
            }

            if (RangesIntersects(Add.RentRanges, rentFrom, rentTo))
            {
                return(RedirectToAction(nameof(Details), new { id = id }));
            }

            var rentRange = new RentRange {
                RentFrom = rentFrom, RentTo = rentTo, Status = RentStatus.Pending
            };
            var req = new AdvertiseRequest();

            req.From   = Int32.Parse(HttpContext.Session.GetString("sId"));
            req.Type   = AdvertiseRequest.RequestToBook;
            req.Status = Advertise.StatusPending;
            req.AdvID  = id;

            var to_id = from a in _context.User select a;

            to_id = to_id.Where(e => e.Email == Add.UserMail);

            req.To = to_id.ToList()[0].ID;

            _context.AdvertiseRequest.Add(req);

            Add.RentRanges.Add(rentRange);
            _context.SaveChanges();

            var task = Task.Run(async() =>
            {
                using (var es = _emailService.SendEmailAsync(Add.UserMail, "You have a request to rent your house", $"Your house {Add.Address} want to be rented"))
                {
                    await es;
                }
            });

            var task2 = Task.Run(async() =>
            {
                using (var es = _emailService.SendEmailAsync(HttpContext.Session.GetString("sEmail"), "Booking request", $"Your booking request on hose {Add.Address} handling"))
                {
                    await es;
                }
            });

            return(RedirectToAction(nameof(Index)));
        }
Пример #2
0
        /// <summary>
        /// Higher rent means lower sqm price
        /// </summary>
        /// <param name="rentRange"></param>
        /// <returns></returns>
        private double GetRentFactor(RentRange rentRange)
        {
            const double RentFactor = 0.30; // +- 30% on square meter price depending on if an apartment is below or abov average rent

            switch (rentRange)
            {
            case RentRange.Average:
                return(1);

            case RentRange.Above:
                return(1 - RentFactor);

            case RentRange.Below:
                return(1 + RentFactor);

            default:
                throw new Exception($"unexpected renr range type: {rentRange}");
            }
        }