Example #1
0
 public ActionResult Create(ReservationViewModel reservation)
 {
     if (ModelState.IsValid)
     {
         Reservation reservationInstance = ReservationMapper.Map(reservation);
         var         result = _unitOfWork.Reservation_List.AddWithRooms(reservationInstance, reservation.SelectedRooms);
         if (result)
         {
             if (reservation.SelectedFellows != null)
             {
                 _unitOfWork.Customer_List.ConvertCustomersToFellow(reservation.ParentId, reservation.SelectedFellows);
             }
             Ok();
             Task.Run(() => ReservationJobs.Start(reservationInstance.ID, DateTime.Now.AddDays(1))); // Quartz
             return(RedirectToAction("Index", "Reservation", null));
         }
     }
     Forbidden();
     return(Content(GenerateError()));
 }
Example #2
0
        public IHttpActionResult Create(ReservationViewModel reservation)
        {
            if (ModelState.IsValid)
            {
                reservation.ParentId = _unitOfWork.Customer_List.GetAll().Where(w => w.Person_ApplicationUser != null)
                                       .FirstOrDefault(w => w.Person_ApplicationUser.Id == reservation.ParentId).ID.ToString();
                Reservation rsv    = ReservationMapper.Map(reservation);
                var         result = _unitOfWork.Reservation_List.AddWithRooms(rsv, reservation.SelectedRooms);
                if (result)
                {
                    if (reservation.SelectedFellows != null)
                    {
                        _unitOfWork.Customer_List.ConvertCustomersToFellow(reservation.ParentId, reservation.SelectedFellows);
                    }
                    Ok();
                    Task.Run(() => ReservationJobs.Start(rsv.ID, DateTime.Now.AddDays(1)));
                    string Number = _unitOfWork.Reservation_List.Find(rsv.ID).Number.ToString();


                    int         days     = (rsv.ToDate - rsv.FromDate).Days + 1;
                    int         Price    = 0;
                    Reservation savedRes = _unitOfWork.Reservation_List.Find(rsv.ID);
                    foreach (var reservationRooms in savedRes.Reservation_ReservationRooms_List)
                    {
                        var data = _unitOfWork.RoomPrice_List.GetAll().Where(w => w.RoomID == reservationRooms.RoomID);
                        if (data != null)
                        {
                            Price += ((data.Where(w => w.Date == savedRes.FromDate).OrderByDescending(c => c.CreateDate).FirstOrDefault().Price) / 2);
                        }
                    }
                    Price *= days;
                    return(Json(new { number = Number, price = Price }));
                }
            }
            return(BadRequest());
        }