Пример #1
0
        public ActionResult Edit(ReservationViewModel reservation)
        {
            if (ModelState.IsValid)
            {
                var result = _unitOfWork.Reservation_List.UpdateWithRooms(ReservationMapper.Map(reservation), reservation.SelectedRooms);

                if (result)
                {
                    if (reservation.SelectedFellows != null)
                    {
                        _unitOfWork.Customer_List.UpdateFellows(reservation.ParentId, reservation.SelectedFellows);
                    }
                    Ok();
                    Reservation reservationSignalR = _unitOfWork.Reservation_List.Find(Guid.Parse(reservation.ID));
                    var         hub = new dashboardHub();
                    hub.Refresh(
                        reservationSignalR.ID.ToString(),
                        Translator.ReservationStateToPersian(reservationSignalR.Reservation_ReservationState.Title.ToString()),
                        reservationSignalR.Number.ToString(),
                        PersianDateConvertor.ConvertToPersianDate(reservationSignalR.FromDate, true),
                        PersianDateConvertor.ConvertToPersianDate(reservationSignalR.ToDate, true)
                        );
                    Response.Redirect("/Admin/Home/Index");
                    return(RedirectToAction("Index", "Reservation", null));
                }
            }
            Forbidden();
            return(Content(GenerateError()));
        }
Пример #2
0
        public async Task <IEnumerable <Reservation> > GetAllReservationsAsync()
        {
            var reservation = await this.unitOfWork.ReservationRepository.GetAllAsync();

            IList <Reservation> reservationList = new List <Reservation>();

            reservation.ToList().ForEach(i => reservationList.Add(ReservationMapper.Map(i)));

            return(reservationList);
        }
Пример #3
0
        /// <summary>
        /// Updates a reservation.
        /// </summary>
        /// <param name="reservationId">Reservation identifier.</param>
        /// <param name="reservationResource">New reservation information</param>
        /// <returns>Reservation information.</returns>
        public async Task <DataResponse <ReservationResource> > UpdateAsync(int reservationId,
                                                                            SaveReservationResource reservationResource)
        {
            try
            {
                if (reservationResource == null)
                {
                    throw new ArgumentNullException(nameof(reservationResource));
                }

                var reservation = await _reservationRepository.FindByIdAsync(reservationId);

                if (reservation == null)
                {
                    throw new NotFoundException(nameof(Reservation), reservationId);
                }

                var place = await _placeRepository.FindByIdAsync(reservationResource.PlaceId);

                reservation.Place = place
                                    ?? throw new NotFoundException(nameof(Place), reservationResource.PlaceId);

                if (reservationResource.Contact != null)
                {
                    var contact = await _contactRepository.FirstOrDefaultAsync(
                        new ContactsByNameSpec(reservationResource.Contact.Name));

                    if (contact != null)
                    {
                        ContactMapper.Map(contact, reservationResource.Contact);
                        reservation.Contact = contact;
                    }
                    else
                    {
                        reservation.Contact = _mapper.Map <Contact>(reservationResource.Contact);
                    }
                }

                ReservationMapper.Map(reservation, reservationResource);
                _reservationRepository.Update(reservation);
                await _unitOfWork.SaveChangesAsync();

                var resource = _mapper.Map <ReservationResource>(reservation);
                return(new DataResponse <ReservationResource>(resource));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(new DataResponse <ReservationResource>(ex.Message));
            }
        }
Пример #4
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()));
 }
Пример #5
0
        public IHttpActionResult AddTempReservation(List <ReservationViewModel> instances)
        {
            List <ReservationResult> reservationResults = new List <ReservationResult>();

            foreach (ReservationViewModel item in instances)
            {
                item.State = "4c825c2b-ad88-48d5-af69-277d97351651";
                Reservation reservation = ReservationMapper.Map(item);
                var         result      = _unitOfWork.Reservation_List.AddWithRooms(reservation, item.SelectedRooms);
                if (result)
                {
                    if (item.SelectedFellows != null)
                    {
                        _unitOfWork.Customer_List.ConvertCustomersToFellow(item.ParentId, item.SelectedFellows);
                    }
                }
                _unitOfWork.Complete();

                int         days     = (reservation.ToDate - reservation.FromDate).Days + 1;
                int         price    = 0;
                Reservation savedRes = _unitOfWork.Reservation_List.Find(reservation.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;

                reservationResults.Add(new ReservationResult()
                {
                    ID     = savedRes.ID.ToString(),
                    Number = savedRes.Number.ToString(),
                    State  = Translator.ReservationStateToPersian(_unitOfWork.ReservationState_List.Find(savedRes.ReservationStateID).Title.ToString()),
                    Price  = price.ToString()
                });
            }
            return(Ok(reservationResults));
        }
Пример #6
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());
        }