Esempio n. 1
0
        public Audit <TableBooking> SaveBooking(TableBooking booking, string createdBy, DateTimeOffset createdAt)
        {
            var auditedBooking = new Audit <TableBooking>(booking, createdBy, createdAt);

            _bookings.Add(auditedBooking);
            return(auditedBooking);
        }
        public TableBooking FindBy(Guid key)
        {
            TableBooking booking = null;

            string sql = "SELECT TOP 1  BookingDate, FirstName, LastName, PhoneNumber, Email, Request, "
                         + "CreateTime, Status, BookingNumber, NumberOfAdults, NumberOfChildren "
                         + "FROM [AP_TableBookings] "
                         + "WHERE RowID = @id AND Status<>99";

            SqlParameter[] sp  = new SqlParameter[] { new SqlParameter("@id", key) };
            SqlDataReader  sdr = SqlHelper.ExecuteReader(_connection, CommandType.Text, sql, sp);

            while (sdr.Read())
            {
                booking = new TableBooking(key,
                                           sdr["BookingNumber"].ToString(),
                                           sdr["NumberOfAdults"].ToString(),
                                           sdr["NumberOfChildren"].ToString(),
                                           Convert.ToDateTime(sdr["BookingDate"]),
                                           sdr["FirstName"].ToString(),
                                           sdr["LastName"].ToString(),
                                           sdr["PhoneNumber"].ToString(),
                                           sdr["Email"].ToString(),
                                           sdr["Request"].ToString(),
                                           Convert.ToDateTime(sdr["CreateTime"]),
                                           (TableBookingStatus)Convert.ToInt32(sdr["Status"]));
            }
            sdr.Close();

            return(booking);
        }
Esempio n. 3
0
        private TableRentalViewModel getVMFromTableBook(TableBooking bookRent)
        {
            Table tableSelected = db.Tables.Where(x => x.Id == bookRent.TableId).FirstOrDefault();

            var userDetails = from u in db.Users
                              where u.Id.Equals(bookRent.UserId)
                              select new { u.Id, u.FirstName, u.Surname, u.Email };

            TableRentalViewModel model = new TableRentalViewModel
            {
                Id          = bookRent.Id,
                TableId     = tableSelected.Id,
                Name        = tableSelected.Name,
                Description = tableSelected.Description,
                Image       = tableSelected.Image,
                Avaibility  = tableSelected.Avaibility,
                BookingMade = bookRent.BookingMade,
                BookingDate = bookRent.BookingDate,
                BookingTime = bookRent.BookingTime,
                Seats       = bookRent.Seats,
                TableNumber = bookRent.TableNumber,
                Status      = bookRent.Status.ToString(),
                Email       = userDetails.ToList()[0].Email,
                FirstName   = userDetails.ToList()[0].FirstName,
                LastName    = userDetails.ToList()[0].Surname,
                UserId      = userDetails.ToList()[0].Id
            };

            return(model);
        }
        public void ShouldSaveTableBookerOnDataBase()
        {
            //Arrange
            var _request = new TableBooking
            {
                Name       = "Pedro",
                LastName   = "Díaz",
                BookerDate = new DateTime(2021, 10, 15),
                Email      = "*****@*****.**"
            };

            TableBooking savedTableBooker = null;

            _tableBookerRepository.Setup(repository => repository.Save(It.IsAny <TableBooking>()))
            .Callback <TableBooking>(tableBooker =>
                                     savedTableBooker = tableBooker
                                     );

            //Act
            var result = _processor.BookTable(_request);

            //Asserts
            _tableBookerRepository.Verify(repository => repository.Save(It.IsAny <TableBooking>()), Times.Once);

            Assert.NotNull(result);
            Assert.Equal(savedTableBooker.Name, result.Name);
            Assert.Equal(savedTableBooker.LastName, result.LastName);
            Assert.Equal(savedTableBooker.BookerDate, result.BookerDate);
            Assert.Equal(savedTableBooker.Email, result.Email);
        }
        public void PersistCreationOf(IAggregateRoot root)
        {
            TableBooking booking = root as TableBooking;

            string sql = "INSERT INTO [AP_TableBookings] (NumberOfAdults, NumberOfChildren, BookingDate, FirstName, "
                         + "LastName, PhoneNumber, Email, Request, CreateTime, BookingNumber, Status, RowID) "
                         + "VALUES (@numofadults, @numofchildren, @bookingdate, @firstname, @lastname, @phonenum, @email,"
                         + " @request, @createtime, @bookingnum, @status, @rid)";

            SqlParameter[] sp = new SqlParameter[] {
                new SqlParameter("@numofadults", booking.Numberofadults),
                new SqlParameter("@numofchildren", booking.Numberofchildren),
                new SqlParameter("@bookingdate", booking.Bookingdate),
                new SqlParameter("@firstname", booking.Firstname),
                new SqlParameter("@lastname", booking.Lastname),
                new SqlParameter("@phonenum", booking.Phonenumber),
                new SqlParameter("@email", booking.Email),
                new SqlParameter("@request", booking.Request),
                new SqlParameter("@createtime", booking.Createtime),
                new SqlParameter("@bookingnum", booking.Bookingnumber),
                new SqlParameter("@status", booking.Status),
                new SqlParameter("@rid", booking.Id)
            };

            SqlHelper.ExecuteNonQuery(_connection, CommandType.Text, sql, sp);
        }
Esempio n. 6
0
        //Approve GET Method
        public ActionResult Approve(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            TableBooking tableBook = db.Booking.Find(id);

            var model = getVMFromTableBook(tableBook);

            if (model == null)
            {
                return(HttpNotFound());
            }

            return(View("Approve", model));

            //tableBook.Status = TableBooking.StatusEnum.Approved;

            //db.SaveChanges();


            //return RedirectToAction("Index", "TableBook");
        }
Esempio n. 7
0
        public ActionResult Reserve(TableRentalViewModel book)
        {
            var   userid      = User.Identity.GetUserId();
            Table tableToRent = db.Tables.Find(book.TableId);

            if (book.Seats <= 10)
            {
                var userInDb = db.Users.SingleOrDefault(c => c.Id == userid);

                TableBooking tableBook = new TableBooking
                {
                    TableId     = tableToRent.Id,
                    UserId      = userid,
                    BookingMade = DateTime.Now,
                    BookingDate = book.BookingDate,
                    BookingTime = book.BookingTime,
                    Seats       = book.Seats,
                    Status      = TableBooking.StatusEnum.Requested,
                };

                db.Booking.Add(tableBook);
                var tableInDb = db.Tables.SingleOrDefault(c => c.Id == book.TableId);

                tableInDb.Avaibility -= 1;

                db.SaveChanges();
                return(RedirectToAction("Index", "TableBook"));
            }
            else
            {
                ViewBag.Errors = "You cannot book more than 10 seats!";
                return(RedirectToAction("Index", new RouteValueDictionary(
                                            new { controller = "TableDetail", action = "Index", Id = book.TableId })));
            }
        }
        public IQueryable <TableBooking> FindAll()
        {
            List <TableBooking> bookings = new List <TableBooking>();

            string sql = "SELECT RowID, BookingNumber, NumberOfAdults, NumberOfChildren, BookingDate, FirstName, "
                         + "LastName, PhoneNumber, Email, Request, CreateTime, Status "
                         + "FROM [AP_TableBookings] "
                         + "WHERE Status<>99";
            SqlDataReader sdr = SqlHelper.ExecuteReader(_connection, CommandType.Text, sql);

            while (sdr.Read())
            {
                TableBooking booking = new TableBooking(new Guid(sdr["RowID"].ToString()),
                                                        sdr["BookingNumber"].ToString(),
                                                        sdr["NumberOfAdults"].ToString(),
                                                        sdr["NumberOfChildren"].ToString(),
                                                        Convert.ToDateTime(sdr["BookingDate"]),
                                                        sdr["FirstName"].ToString(),
                                                        sdr["LastName"].ToString(),
                                                        sdr["PhoneNumber"].ToString(),
                                                        sdr["Email"].ToString(),
                                                        sdr["Request"].ToString(),
                                                        Convert.ToDateTime(sdr["CreateTime"]),
                                                        (TableBookingStatus)Convert.ToInt32(sdr["Status"]));
                bookings.Add(booking);
            }
            sdr.Close();
            return(bookings.AsQueryable());
        }
Esempio n. 9
0
        public void DeleteTableBooking(Guid pBookingID)
        {
            TableBooking lTableBooking = BookingContext.TableBooking.Find(pBookingID);

            if (lTableBooking != null)
            {
                BookingContext.TableBooking.Remove(lTableBooking);
            }
        }
Esempio n. 10
0
 public void Save(TableBookingDetailDto dto)
 {
     using (_context)
     {
         IRepository <TableBooking> tableBookingRep = _context.GetRepository <TableBooking>();
         TableBooking booking = Mapper.Map <TableBookingDetailDto, TableBooking>(dto);
         tableBookingRep.Save(booking);
         _context.SaveChanges();
     }
 }
Esempio n. 11
0
 public void Add(NewTableBookingDto dto)
 {
     using (_context)
     {
         IRepository <TableBooking> tableBookingRep = _context.GetRepository <TableBooking>();
         TableBooking booking = Mapper.Map <NewTableBookingDto, TableBooking>(dto);
         tableBookingRep.Add(booking);
         _context.SaveChanges();
     }
 }
Esempio n. 12
0
        public TableBookingDetailDto GetByKey(string bid)
        {
            using (_context)
            {
                IRepository <TableBooking> tableBookingRep = _context.GetRepository <TableBooking>();
                TableBooking          tb  = tableBookingRep.FindBy(new Guid(bid));
                TableBookingDetailDto dto = Mapper.Map <TableBooking, TableBookingDetailDto>(tb);

                return(dto);
            }
        }
        public void PersistDeletionOf(IAggregateRoot root)
        {
            TableBooking booking = root as TableBooking;
            string       sql     = "UPDATE [AP_TableBookings] SET Status = 99 WHERE RowID =  @rid";

            SqlParameter[] sp = new SqlParameter[] {
                new SqlParameter("@rid", booking.Id)
            };

            SqlHelper.ExecuteNonQuery(_connection, CommandType.Text, sql, sp);
        }
Esempio n. 14
0
        //PickUp Get Method
        public ActionResult CheckIn(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            TableBooking tableBook = db.Booking.Find(id);

            tableBook.Status = TableBooking.StatusEnum.CheckedIn;

            db.SaveChanges();


            return(RedirectToAction("Index", "TableBook"));
        }
Esempio n. 15
0
        //Delete GET Method
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            TableBooking tableBook = db.Booking.Find(id);
            Table        tableInDb = db.Tables.Find(tableBook.TableId);

            tableInDb.Avaibility += 1;
            db.Booking.Remove(tableBook);
            db.SaveChanges();

            return(RedirectToAction("Index", "TableBook"));
        }
Esempio n. 16
0
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TableBooking bookRent = db.Booking.Find(id);

            var model = getVMFromTableBook(bookRent);

            if (model == null)
            {
                return(HttpNotFound());
            }

            return(View(model));
        }
Esempio n. 17
0
        public void SendEmail(int id)
        {
            TableBooking    tableBook = db.Booking.Find(id);
            ApplicationUser user      = db.Users.Find(tableBook.UserId);
            Table           table     = db.Tables.Find(tableBook.TableId);

            string fullName = user.FirstName + " " + user.Surname;

            string orderMessage =
                $"Hello, {fullName}! \n\n" +
                $"Your table booking with DUT Rendezvous Restaurant has been approved! \n\n" +
                $"Your order details are as follows: \n" +
                $"Booking Type: {table.Name} \n" +
                $"Booking Date: {tableBook.BookingDate.Value.ToLongDateString()} @ {tableBook.BookingTime.Value.ToShortTimeString()} \n" +
                $"Number of seats: {tableBook.Seats} \n" +
                $"Table Number: {tableBook.TableNumber} \n\n" +
                $"Can't wait to have you dine with us :)";

            //SendEmail
            var senderEmail  = new MailAddress("*****@*****.**", "Rendezvous Restaurant");
            var recieverMail = new MailAddress(user.UserName, fullName);
            var password     = "******";
            var sub          = $"New Booking #{tableBook.Id}!";
            var body         = orderMessage;

            var smtp = new SmtpClient
            {
                Host                  = "smtp.gmail.com",
                Port                  = 587,
                EnableSsl             = true,
                DeliveryMethod        = SmtpDeliveryMethod.Network,
                UseDefaultCredentials = false,
                Credentials           = new NetworkCredential(senderEmail.Address, password)
            };

            using (var mess = new MailMessage(senderEmail, recieverMail)
            {
                Subject = sub,
                Body = body
            })
            {
                smtp.Send(mess);
            }
        }
Esempio n. 18
0
        public void Should_save_request_booking()
        {
            TableBooking savedBooking = null;

            _bookingRepository.Setup(_ => _.SaveBooking(It.IsAny <TableBooking>()))
            .Callback <TableBooking>(tableBooking => {
                savedBooking = tableBooking;
            });

            var result = _processor.BookTable(_request);

            _bookingRepository.Verify(_ => _.SaveBooking(It.IsAny <TableBooking>()), Times.Once);
            Assert.IsNotNull(savedBooking);
            Assert.AreEqual(savedBooking.FirstName, _request.FirstName);
            Assert.AreEqual(savedBooking.LastName, _request.LastName);
            Assert.AreEqual(savedBooking.Email, _request.Email);
            Assert.AreEqual(savedBooking.Date, _request.Date);
            Assert.AreEqual(_tables.First().Id, savedBooking.TableId);
        }
Esempio n. 19
0
        public ActionResult Approve(TableRentalViewModel model)
        {
            if (model.Id == 0)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            if (ModelState.IsValid)
            {
                TableBooking tableBook = db.Booking.Find(model.Id);
                tableBook.Status      = TableBooking.StatusEnum.Approved;
                tableBook.TableNumber = model.TableNumber;

                db.SaveChanges();
            }

            SendEmail(model.Id);

            return(RedirectToAction("Index", "TableBook"));
        }
        public void ShouldReturnTheSameDataEntered()
        {
            //Arrange
            var _request = new TableBooking
            {
                Name       = "Pedro",
                LastName   = "Díaz",
                BookerDate = new DateTime(2021, 10, 15),
                Email      = "*****@*****.**"
            };

            //Act
            var result = _processor.BookTable(_request);

            //Asserts
            Assert.NotNull(result);
            Assert.Equal(_request.Name, result.Name);
            Assert.Equal(_request.LastName, result.LastName);
            Assert.Equal(_request.BookerDate, result.BookerDate);
            Assert.Equal(_request.Email, result.Email);
        }
        public void PersistUpdateOf(IAggregateRoot root)
        {
            TableBooking booking = root as TableBooking;

            string sql = "UPDATE [AP_TableBookings] SET NumberOfAdults = @numofadults, NumberOfChildren = @numofchildren, BookingDate = @bookingdate, "
                         + "FirstName = @firstname, LastName = @lastname, PhoneNumber = @phonenum, Email = @email, Request = @request, "
                         + "Status = @status WHERE RowID =  @rid";

            SqlParameter[] sp = new SqlParameter[] {
                new SqlParameter("@numofadults", booking.Numberofadults),
                new SqlParameter("@numofchildren", booking.Numberofchildren),
                new SqlParameter("@bookingdate", booking.Bookingdate),
                new SqlParameter("@firstname", booking.Firstname),
                new SqlParameter("@lastname", booking.Lastname),
                new SqlParameter("@phonenum", booking.Phonenumber),
                new SqlParameter("@email", booking.Email),
                new SqlParameter("@request", booking.Request),
                new SqlParameter("@status", booking.Status),
                new SqlParameter("@rid", booking.Id)
            };

            SqlHelper.ExecuteNonQuery(_connection, CommandType.Text, sql, sp);
        }
        public void SaveTableBooking()
        {
            //Arrange
            TableBooking savedTableBooking = null;

            _tableBookerRepositoyMock.Setup(repository => repository.Save(It.IsAny <TableBooking>()))
            .Callback <TableBooking>(tableBooking =>
            {
                savedTableBooking = tableBooking;
            });

            //Act
            _processor.BookTable(_request);

            _tableBookerRepositoyMock.Verify(repository => repository.Save(It.IsAny <TableBooking>()), Times.Once);

            //Assert
            Assert.NotNull(savedTableBooking);
            Assert.Equal(savedTableBooking.FirstName, _request.FirstName);
            Assert.Equal(savedTableBooking.LastName, _request.LastName);
            Assert.Equal(savedTableBooking.Email, _request.Email);
            Assert.Equal(savedTableBooking.ReservationDate, _request.ReservationDate);
        }
 public void Remove(TableBooking booking)
 {
     _context.RegisterRemoved(booking, this);
 }
Esempio n. 24
0
 public void UpdateTableBooking(TableBooking pTableBooking)
 {
     BookingContext.Entry(pTableBooking).State = EntityState.Modified;
 }
Esempio n. 25
0
 public void InsertTableBooking(TableBooking pTableBooking)
 {
     BookingContext.TableBooking.Add(pTableBooking);
 }
Esempio n. 26
0
 public void SaveBooking(TableBooking booking)
 {
     booking.SetAuditInfo(CurrentContext.CurrentUser, DateTimeOffset.Now);
     _bookings.Add(booking);
 }
 public void Add(TableBooking booking)
 {
     _context.RegisterNew(booking, this);
 }
 public void Save(TableBooking booking)
 {
     _context.RegisterAmended(booking, this);
 }