Example #1
0
        public ReservationViewModel AddReservation(ReservationViewModel model)
        {
            var reservationModel = mapper.Map <Reservation>(model);
            var reservation      = reservationRepository.AddReservation(reservationModel);

            return(mapper.Map <ReservationViewModel>(reservation));
        }
 public void AddReservation()
 {
     try
     {
         Reservation reservation = new Reservation();
         Console.WriteLine("Print GuestId: ");
         reservation.GuestId = Int32.Parse(Console.ReadLine());
         Console.WriteLine("Print RoomId: ");
         reservation.RoomId = Int32.Parse(Console.ReadLine());
         Console.WriteLine("Print ReservationDate: ");
         reservation.ReservationDate = DateTime.Parse(Console.ReadLine());
         Console.WriteLine("Print CheckInDate: ");
         reservation.CheckInDate = DateTime.Parse(Console.ReadLine());
         Console.WriteLine("Print CheckOutDate: ");
         reservation.CheckOutDate = DateTime.Parse(Console.ReadLine());
         Console.WriteLine("Print PersonCount: ");
         reservation.PersonCount = Int32.Parse(Console.ReadLine());
         reservationService.AddReservation(reservation);
         Console.WriteLine("Object Added updated");
         ConsoleReservationPresenter.Present(reservationService.ReadReservations());
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         AddReservation();
     }
 }
Example #3
0
        public async Task <int> AddReservation(ReservationViewModel model)
        {
            try
            {
                Reservation reservation = _mapper.Map <Reservation>(model);


                //Finding contact by name to know if exits
                var tempContact = _repoContact.GetContactByName(model.ContactName);
                if (tempContact.Id == 0)
                {
                    //Trying other way to map
                    Contact contact = new Contact
                    {
                        Name          = model.ContactName,
                        PhoneNumber   = model.PhoneNumber,
                        Birth         = model.Birth,
                        ContactTypeId = model.ContactTypeId
                    };
                    //Adding contact if not exists
                    await _repoContact.AddContact(contact);
                }
                var result = await _repo.AddReservation(reservation);

                //Returning Reservation Id
                return(result);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public void AddReservation(Guest guest, int roomTypeId, DateTime startDate, DateTime endDate)
        {
            _guestRepository.InsertGuest(guest);

            List <Room> availableRooms = _roomRepository.GetAvailableRooms(startDate, endDate, roomTypeId);

            _reservationRepository.AddReservation(availableRooms.First().Id, guest.Id, startDate, endDate);
        }
Example #5
0
        public async Task <IActionResult> AddReservation(DataViewModel data)
        {
            var user = await(_userManager.GetUserAsync(User));

            data.guest = _userRepository.AddUser(user);
            _reservationRepository.AddReservation(data);
            _roomRepository.UpdateRoom(data);

            return(PartialView("_Success"));
        }
        public async Task <ActionResult> Edit(ReservationViewModel reservationVM)
        {
            TempData["message"] = string.Empty;
            string message;
            var    reservation = reservationVM.Reservation;

            if (reservation == null)
            {
                return(View(new ReservationViewModel()));
            }

            bool succeeded;

            //add new reservation
            if (reservation.ReservationID == 0)
            {
                reservation.ReservationTotal = await(from b in _context.Bikes
                                                     where b.BikeID == reservation.BikeID
                                                     select b.HourlyRate).FirstOrDefaultAsync() * (decimal)(reservation.EndDate - reservation.StartDate).TotalHours;
                decimal.Round(reservation.ReservationTotal, 2, MidpointRounding.AwayFromZero);
                reservation.RentedStoreID = await(from s in _context.Stores
                                                  where s.AddressLine1 == reservationVM.SelectedStore
                                                  select s.StoreID).FirstOrDefaultAsync();
                reservation.AccessoriesTotal = 10;
                var res = await repository.AddReservation(reservation);

                string resid = await res.Content.ReadAsStringAsync();

                reservation.ReservationID = Convert.ToInt32(resid);
                succeeded = res.IsSuccessStatusCode;
                message   = $"{reservation.ReservationID} has not been added";

                //Checking the response is successful or not
                if (succeeded)
                {
                    message = $"{reservation.ReservationID} has been added";
                }
            }
            else
            {
                //update existing reservation
                succeeded = await repository.UpdateReservation(reservation);

                message = $"{reservation.ReservationID} has not been saved";
                //Checking the response is successful or not
                if (succeeded)
                {
                    message = $"{reservation.ReservationID} has been saved";
                }
            }
            TempData["message"] = message;

            return(View(reservationVM));
        }
        public Result AddReservation(ICollection <ReservationDto> reservations)
        {
            List <Reservation> reservationsDb = new List <Reservation>();

            foreach (ReservationDto reservation in reservations)
            {
                reservationsDb.Add(parser.ToReservation(reservation));
            }

            return(reservationRepository.AddReservation(reservationsDb));
        }
        public async Task <IActionResult> Reserve(DateTime startTime, int machineId)
        {
            var machine = _washingMachineRepo.GetWashingMachineById(machineId);

            if (!await _authHelpers.CheckDormitoryMembership(User, machine.Laundry.Dormitory))
            {
                return(ControllerHelpers.ShowAccessDeniedErrorPage(this));
            }

            var userId = _userManager.GetUserId(User);
            var roomId = _userRepo.GetUserById(userId).RoomId;

            var reservation = new Reservation()
            {
                StartTime        = startTime,
                RoomId           = roomId,
                WashingMachineId = machineId,
                Fault            = false
            };

            var reservationAtHour = _reservationRepo.GetHourReservation(machineId, startTime);
            var faultAtTime       = _reservationRepo.IsFaultAtTime(machineId, startTime);

            if (reservationAtHour != null ||
                faultAtTime ||
                reservation.StartTime < DateTime.Now)
            {
                return(ControllerHelpers.Show404ErrorPage(this, _localizer));
            }

            if (_reservationRepo.IsCurrentlyFault(machineId))
            {
                return(ControllerHelpers.Show404ErrorPage(this, _localizer));
            }

            if (roomId != null)
            {
                var toRenew         = _reservationRepo.GetRoomToRenewReservation(roomId.Value);
                var roomReservation = _reservationRepo.GetRoomDailyReservation(roomId.Value, startTime);
                if (toRenew != null)
                {
                    _reservationRepo.RemoveReservation(toRenew);
                }
                else if (roomReservation != null)
                {
                    return(ControllerHelpers.Show404ErrorPage(this, _localizer));
                }
            }

            _reservationRepo.AddReservation(reservation);

            return(RedirectToDayByLaundryId(machine.LaundryId, startTime));
        }
        public async Task <ActionResult> Edit(Reservation reservation)
        {
            TempData["message"] = string.Empty;
            string message;

            if (reservation == null)
            {
                return(View(new ReservationViewModel()));
            }

            bool succeeded;

            //add new reservation
            if (reservation.ReservationID == 0)
            {
                var res = await repository.AddReservation(reservation);

                succeeded = res.IsSuccessStatusCode;
                message   = $"{reservation.ReservationID} has not been added";

                //Checking the response is successful or not
                if (succeeded)
                {
                    message = $"{reservation.ReservationID} has been added";
                }
            }
            else
            {
                //update existing reservation
                succeeded = await repository.UpdateReservation(reservation);

                message = $"{reservation.ReservationID} has not been saved";
                //Checking the response is successful or not
                if (succeeded)
                {
                    message = $"{reservation.ReservationID} has been saved";
                }
            }
            TempData["message"] = message;

            if (succeeded)
            {
                return(RedirectToAction("Index"));
            }

            var model = new ReservationViewModel
            {
                Reservation = reservation
            };

            return(View(model));
        }
Example #10
0
        public IReservation AddReservation(IReservation reservation)
        {
            var availability = GetAvailability(reservation);

            CheckForNoFreeSpaces(availability);
            var addedReservation = reservationRepository.FindReservationById(reservation.Id);

            addedReservation.Id        = reservation.Id;
            addedReservation.CarParkId = reservation.CarParkId;
            addedReservation.FromDate  = reservation.FromDate;
            addedReservation.ToDate    = reservation.ToDate;
            reservationRepository.AddReservation(addedReservation);
            return(new Reservation(addedReservation.Id, addedReservation.CarParkId, addedReservation.FromDate, addedReservation.ToDate));
        }
Example #11
0
        public ActionResult <ReservationsDto> CreateReservationForClient(int clientId, ReservationForCreationDto reservation)
        {
            if (!_clientRepository.ClientExists(clientId))
            {
                return(NotFound());
            }

            var reservationEntity = _mapper.Map <Entities.Reservation>(reservation);

            _reservationRepository.AddReservation(reservationEntity, clientId);
            _reservationRepository.Save();

            var reservationToReturn = _mapper.Map <ReservationsDto>(reservationEntity);

            return(CreatedAtRoute("GetReservationForClient",
                                  new { clientId = clientId, reservationId = reservationToReturn.ReservationId }, reservationToReturn));
        }
 private void editcreateuserbtn_Click(object sender, EventArgs e)
 {
     if (iscorrectfin)
     {
         if (string.IsNullOrEmpty(fintxtbox.Text))
         {
             MessageBox.Show("Fill all fields", "Warning!!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
             return;
         }
         if (fintxtbox.Text.Length < 7)
         {
             MessageBox.Show("Invalid FIN", "Warning!!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
             return;
         }
         Reservation reservation = new Reservation()
         {
             CheckInDate  = checkindate.Value,
             CheckOutDate = checkoutdate.Value,
             RoomId       = roomcombobox.SelectedValue != null?Convert.ToInt32(roomcombobox.SelectedValue) : 0
         };
         if (isEdit)
         {
             reservation.Id = reservid;
             reservationRepository.UpdateReservation(reservation);
             MessageBox.Show("Reservation Edited", "Edited", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
         else
         {
             reservationRepository.AddReservation(reservation, fintxtbox.Text);
             MessageBox.Show("Reservation Created", "Created", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
         reservationgrid.DataSource = reservationRepository.GetReservations();
         BindRoomCombobox();
         clearbtn_Click(sender, e);
     }
     else
     {
         MessageBox.Show("Invalid FIN", "Warning!!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         return;
     }
 }
        public async Task AddReservationAsync(Reservation reservation)
        {
            try
            {
                var user = userRepository.Users.SingleOrDefault(u => u.UserId == reservation.UserId);
                //Creare Eccezione custom
                reservation.User = user ?? throw new Exception();
                var field = fieldRepository.Fields.SingleOrDefault(f => f.FieldId == reservation.FieldId);
                reservation.Field = field ?? throw new Exception();
                reservation.Sport = ToSport(reservation.Field.GetType().Name);

                if (reservation.Price == 0)
                {
                    if (reservation.IsDoubleReservation())
                    {
                        reservation.Field.Players = 4;
                        reservation.Price         = reservation.Field.Price * ((reservation.TimeEnd.Hour - reservation.TimeStart.Hour) + (reservation.TimeEnd.Minute - reservation.TimeStart.Minute) / 60) * 1.5m;
                    }
                    else
                    {
                        reservation.Price = reservation.Field.Price * ((reservation.TimeEnd.Hour - reservation.TimeStart.Hour) + (reservation.TimeEnd.Minute - reservation.TimeStart.Minute) / 60);
                    }
                    user.SpentMoney += reservation.Price;
                }
                if (reservation.IsChallenge)
                {
                    reservation.Challenge             = new Challenge(reservation.Field.Players);
                    reservation.Challenge.Reservation = reservation;
                    //user.Challenges++;
                }
                reservationRepository.AddReservation(reservation);
                await context.SaveChangesAsync();

                user.Reservations++;
            }
            catch (DbUpdateException)
            {
            }
        }
        public async Task <IActionResult> AddReservation([FromBody] Reservation Reservation)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var ReservationId = await _ReservationRepository.AddReservation(Reservation);

                    if (ReservationId > 0)
                    {
                        return(Ok(ReservationId));
                    }
                    else
                    {
                        return(NotFound());
                    }
                }
                catch (Exception)
                {
                    return(BadRequest());
                }
            }
            return(BadRequest());
        }
Example #15
0
        public async Task <IActionResult> AddOrEdit(DetailsReservationViewModel detailsReservationViewModel)
        {
            detailsReservationViewModel.Reservation.ObjectForRent = _objectForRents.FirstOrDefault(x => x.ObjectForRentId == detailsReservationViewModel.ObjectForRentId);
            detailsReservationViewModel.Reservation.Customer      = _customers.FirstOrDefault(x => x.CustomerId == detailsReservationViewModel.CustomerId);

            string Message;

            //Insert
            if (detailsReservationViewModel.Reservation.ReservationId == 0)
            {
                await _reservationRepository.AddReservation(detailsReservationViewModel.Reservation);

                Message = "Dodano rezerwację";
            }
            //Update
            else
            {
                bool value = await _reservationRepository.UpdateReservation(detailsReservationViewModel.Reservation);

                if (value == false)
                {
                    return(Json(new { message = "Edycja rezerwacji się nie powiódła", style = "error" }));
                }
                Message = "Edycja rezerwacji przebiegła pomyślnie";
            }

            var FT = detailsReservationViewModel.fromDate;
            var UT = detailsReservationViewModel.untilDate;

            detailsReservationViewModel.fromDate  = new DateTime(FT.Year, FT.Month, FT.Day, 0, 0, 0);
            detailsReservationViewModel.untilDate = new DateTime(UT.Year, UT.Month, UT.Day, 23, 59, 59);

            var reservations = await _reservationRepository.GetReservations(detailsReservationViewModel.fromDate, detailsReservationViewModel.untilDate);

            return(Json(new { isValid = true, html = Helper.RenderRazorViewToString(this, "ReservationsList", new ReservationViewModel(reservations, FT, UT)), message = Message, style = "success" }));
        }
Example #16
0
        public ActionResult AddReservation(Reservation reservation, string Nickname, string TOUS, string FROMUS, string All)
        {
            string[] Times = TOUS.Split('.');
            int      to;

            Int32.TryParse(Times[0], out to);

            string[] Times1 = FROMUS.Split('.');
            int      from;

            Int32.TryParse(Times1[0], out from);

            bool CanBeReached = true;



            foreach (var Rezerwacja in reservationRepository.reservations)
            {
                if (Rezerwacja.PlaneName == reservation.PlaneName && Rezerwacja.Date == reservation.Date)
                {
                    if (to < Rezerwacja.From && from > Rezerwacja.To)
                    {
                        CanBeReached = false;
                    }
                    else if (to > Rezerwacja.From && from > Rezerwacja.To)
                    {
                        if (to - Rezerwacja.To < 0)
                        {
                            CanBeReached = false;
                        }
                    }
                    else if (to >= Rezerwacja.From && from <= Rezerwacja.To)
                    {
                        CanBeReached = false;
                    }
                    else if (to < Rezerwacja.From && from < Rezerwacja.To)
                    {
                        if (Rezerwacja.From - from < 0)
                        {
                            CanBeReached = false;
                        }
                    }
                    else
                    {
                        CanBeReached = false;
                    }
                }
            }



            if (CanBeReached == true)
            {
                reservation.ReservationID = 0;
                reservation.From          = to;
                reservation.To            = from;
                reservationRepository.AddReservation(reservation);
                TempData["message"] = "Poprawnie dodano rezerwacje!";
            }
            else
            {
                TempData["message"] = "Nie udało się dodać rezerwacji , z powodu braku dostępności danych godzin!";
            }
            foreach (var user in usersRepository.Users)
            {
                if (Nickname == user.Username)
                {
                    if (user.Role == "Admin")
                    {
                        if (Convert.ToBoolean(All) == true)
                        {
                            return(RedirectToAction("Index", "Admin", new { usersRepository.GetSpecificName(Nickname).Name, NickName = Nickname, All = true, Date = reservation.Date }));
                        }
                        else
                        {
                            return(RedirectToAction("Index", "Admin", new { usersRepository.GetSpecificName(Nickname).Name, NickName = Nickname, All = false, PlaneName = reservation.PlaneName, Date = reservation.Date }));
                        }
                    }
                    if (user.Role == "Mechanic")
                    {
                        return(RedirectToAction("Index", "Mechanic"));
                    }
                    if (user.Role == "User")
                    {
                        if (Convert.ToBoolean(All) == true)
                        {
                            return(RedirectToAction("Index", "User", new { usersRepository.GetSpecificName(Nickname).Name, NickName = Nickname, All = true, Date = reservation.Date }));
                        }
                        else
                        {
                            return(RedirectToAction("Index", "User", new { usersRepository.GetSpecificName(Nickname).Name, NickName = Nickname, All = false, PlaneName = reservation.PlaneName, Date = reservation.Date }));
                        }
                    }
                }
            }



            return(RedirectToAction("Login", "Login"));
        }
Example #17
0
        public async Task <Reservation> AddReservation(Reservation reservation)
        {
            var res = await _reservationRepository.AddReservation(reservation);

            return(res);
        }
        public ActionResult Completed(RVConfirmationModel model)
        {
            bool sendSuccess = false;

            if (ModelState.IsValid)
            {
                if (model.Message == "Please note that not all requests can be accommodated.")
                {
                    model.Message = "";
                }
                BizInfo   bi  = BizInfoRepository.GetBizInfoById(model.BizInfoId);
                BizRVInfo brv = bi.GetBizRVInfo;
                model.Bizinfo    = bi;
                ViewBag.biztitle = bi.BizTitle;
                ViewBag.datetime = DateTime.Parse(model.RVDate).ToLongDateString() + " " + model.RVTime;
                Reservation r = ReservationRepository.AddReservation(0, brv.BizRVInfoId, model.FirstName, model.LastName, model.Phone,
                                                                     model.Email, model.RVDate, model.RVTime, model.RVNum, model.Message, DateTime.Now, model.FirstName + model.LastName, DateTime.Now, model.FirstName + model.LastName, true);

                if (r != null)
                {
                    EmailManager  em = new EmailManager();
                    EmailContents ec = new EmailContents("FoodReady.Net", model.Email, Globals.Settings.ContactForm.MailFrom,
                                                         "Restaurant Reservation", EmailManager.BuildRVtoCustomerHtmlBody(model));

                    em.FaxBody = EmailManager.BuildRVtoRestaurantHtmlBody(model);
                    em.SendFax(bi.Fax);
                    em.Send(ec); // send to customer

                    if (em.IsSent == false)
                    {
                        sendSuccess = false;
                        TempData["sentCustomerMsg"] = "Your message has not been sent out for some reasons.";
                    }
                    else
                    {
                        sendSuccess = true;
                        TempData["sentCustomerMsg"] = "Your message has  been sent out successfully.";
                    }
                    ec.FromName         = "FoodReady.Net";
                    ec.To               = bi.ContactInfo.Email; // to restaurant;
                    ec.FromEmailAddress = Globals.Settings.ContactForm.MailFrom;
                    ec.Subject          = "Restaurant Reservation";
                    ec.Body             = EmailManager.BuildRVtoRestaurantHtmlBody(model);
                    em.Send(ec);
                    if (em.IsSent == false)
                    {
                        sendSuccess = false;
                        TempData["sentRestaurantMsg"] = "Your message has not been sent out for some reasons.";
                    }
                    else
                    {
                        sendSuccess = true;
                        TempData["sentRestaurantMsg"] = "Your message has  been sent out successfully.";
                    }
                }
                else
                {
                    sendSuccess            = false;
                    TempData["addToDBMsg"] = "Adding reservation to database failed for some reasons.";
                }
            }
            ViewBag.SendingSuccess = sendSuccess;
            return(View(model));
        }
 public long AddReservation(Reservation reservation)
 {
     return(_reservationRepository.AddReservation(reservation));
 }
 public void AddReservation(Reservation reservation)
 {
     _repository.AddReservation(reservation);
 }