private BookingsModel _AddBooking(BookingsModel bookingModel)
        {
            if (bookingModel == null)
            {
                throw new ArgumentNullException(nameof(bookingModel));
            }
            if (bookingModel.Notes.Length > MAXIMUM_NOTE_LENGTH)
            {
                throw new ArgumentException($"Booking Notes {bookingModel.Notes} not valid for model {bookingModel}.");
            }

            string cs   = CONNECTIONSTRING;
            var    conn = new NpgsqlConnection(cs);

            conn.Open();

            string        sql = @"INSERT INTO bookings(vehicleid, clientid, notes, bookingdate) VALUES(" + bookingModel.VehicleId + "," + bookingModel.ClientId + ",'" + bookingModel.Notes + "','" + bookingModel.BookingDate + "'); SELECT CAST(lastval() AS integer)";
            NpgsqlCommand cmd = new NpgsqlCommand(sql, conn);

            int insertedID = Convert.ToInt32(cmd.ExecuteScalar());

            bookingModel.BookingId = insertedID;

            cmd.Dispose();
            conn.Close();

            return(bookingModel);
        }
Пример #2
0
        public ActionResult Book(BookingsModel book)
        {
            book.GoodsList = db.Goods.Select(c => new SelectListItem
            {
                Value = c.GoodID.ToString(),
                Text  = c.GoodName,
            });

            if (db.Customers.Any(u => u.CustomerID == book.CustomerID))
            {
                if (ModelState.IsValid)
                {
                    db.Orders.Add(new Order
                    {
                        Good       = db.Goods.FirstOrDefault(r => r.GoodID == book.GoodID),
                        Customer   = db.Customers.FirstOrDefault(r => r.CustomerID == book.CustomerID),
                        Schedule   = db.Schedules.FirstOrDefault(r => r.ScheduleID == book.SelectedSchedule.ScheduleID),
                        TimeBooked = DateTime.Now
                    });
                    db.SaveChanges();

                    var result = db.Schedules.SingleOrDefault(b => b.ScheduleID == book.SelectedSchedule.ScheduleID);
                    if (result != null)
                    {
                        result.BayLeft = result.BayLeft - 1;
                        db.SaveChanges();
                    }
                    return(RedirectToAction("AgentHome"));
                }
            }
            ViewBag.Error = "Invalid CustomerID";
            return(View(book));
        }
        public List <BookingsModel> GetFilteredBookingSummariesByDateRange(string startDate, string endDate)
        {
            string cs   = CONNECTIONSTRING;
            var    conn = new NpgsqlConnection(cs);

            conn.Open();

            string sql = "SELECT * FROM bookings WHERE bookingdate >= cast('" + startDate + "' AS DATE) AND bookingdate <= cast('" + endDate + "' AS DATE)";
            var    cmd = new NpgsqlCommand(sql, conn);

            NpgsqlDataReader dr = cmd.ExecuteReader();
            var bookings        = new List <BookingsModel>();

            while (dr.Read())
            {
                var booking = new BookingsModel
                {
                    BookingId   = dr.GetInt32(0),
                    ClientId    = dr.GetInt32(1),
                    VehicleId   = dr.GetInt32(2),
                    Notes       = dr.GetString(3),
                    BookingDate = dr.GetDateTime(4)
                };

                bookings.Add(booking);
            }

            conn.Close();
            return(bookings);
        }
        public List <BookingsModel> GetFilteredBookingSummariesByDateRange(DateTime startDate, DateTime endDate)
        {
            string cs  = CONNECTIONSTRING;
            var    con = new NpgsqlConnection(cs);

            con.Open();

            string sql = "SELECT * FROM bookings WHERE bookingDate >= " + startDate + " AND bookingDate <= " + endDate;
            var    cmd = new NpgsqlCommand(sql, con);

            NpgsqlDataReader rdr = cmd.ExecuteReader();
            var bookings         = new List <BookingsModel>();

            while (rdr.Read())
            {
                var booking = new BookingsModel
                {
                    BookingId   = rdr.GetInt32(0),
                    Notes       = rdr.GetString(1),
                    BookingDate = rdr.GetDateTime(2)
                };

                bookings.Add(booking);
            }
            return(bookings);
        }
        public List <BookingsModel> GetBookingDetails()
        {
            string cs   = CONNECTIONSTRING;
            var    conn = new NpgsqlConnection(cs);

            conn.Open();

            string        sql = @"SELECT * FROM bookings";
            NpgsqlCommand cmd = new NpgsqlCommand(sql, conn);

            NpgsqlDataReader dr = cmd.ExecuteReader();
            var bookings        = new List <BookingsModel>();

            while (dr.Read())
            {
                var booking = new BookingsModel
                {
                    BookingId   = dr.GetInt32(0),
                    ClientId    = dr.GetInt32(1),
                    VehicleId   = dr.GetInt32(2),
                    Notes       = dr.GetString(3),
                    BookingDate = dr.GetDateTime(4)
                };

                bookings.Add(booking);
            }

            conn.Close();
            return(bookings);
        }
Пример #6
0
        private static BookingsModel CreateInitialModel()
        {
            var initialModel = new BookingsModel();

            var user1 = new User()
            {
                Name = "Bart"
            };
            var user2 = new User {
                Name = "Homer"
            };

            initialModel.Users.Add(user1.Name, user1);
            initialModel.Users.Add(user2.Name, user1);

            var resource1 = new House(1)
            {
                Name = "Bungalow small", PricePerDay = 800
            };
            var resource2 = new House(2)
            {
                Name = "Bungalow big", PricePerDay = 1200
            };

            initialModel.Resources.Add(1, resource1);
            initialModel.Resources.Add(2, resource2);
            return(initialModel);
        }
 public void InsertBooking(BookingsModel booking)
 {
     booking.IdBooking        = Guid.NewGuid();
     booking.BookingTimeStamp = DateTime.Now;
     dbContext.Bookings.InsertOnSubmit(MapModelToDbObject(booking));
     dbContext.SubmitChanges();
 }
Пример #8
0
        public ActionResult Book(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            BookingsModel bookings = new BookingsModel
            {
                GoodsList = db.Goods.Select(c => new SelectListItem
                {
                    Value = c.GoodID.ToString(),
                    Text  = c.GoodName,
                }),

                SelectedSchedule = db.Schedules.Find(id),
            };

            if (bookings.SelectedSchedule.BayLeft < 1)
            {
                TempData["fullbook"] = "true";
                TempData["msg"]      = "<script>alert('Cannot book this schedule');</script>";
                return(RedirectToAction("BookSchedule"));
            }
            TempData["BookingsModel"] = bookings;
            if (bookings == null)
            {
                return(HttpNotFound());
            }
            return(View(bookings));
        }
        public BookingsModel GetBookingDetailsById(int id)
        {
            string cs   = CONNECTIONSTRING;
            var    conn = new NpgsqlConnection(cs);

            conn.Open();

            string        sql = @"SELECT * FROM bookings WHERE bookingid = " + id;
            NpgsqlCommand cmd = new NpgsqlCommand(sql, conn);

            NpgsqlDataReader dr = cmd.ExecuteReader();
            var booking         = new BookingsModel();

            while (dr.Read())
            {
                var bookingModel = new BookingsModel
                {
                    BookingId   = dr.GetInt32(0),
                    ClientId    = dr.GetInt32(1),
                    VehicleId   = dr.GetInt32(2),
                    Notes       = dr.GetString(3),
                    BookingDate = dr.GetDateTime(4)
                };
                booking = bookingModel;
            }

            conn.Close();
            return(booking);
        }
Пример #10
0
        public ActionResult Edit(Guid id)
        {
            var userId     = User.Identity.GetUserName();
            var floorItems = new List <FloorsModel>();

            if (userRoleRepository.GetRoleByUserName(userId) != null)
            {
                var userRole           = userRoleRepository.GetRoleByUserName(userId).IdUserType;
                var userDepartment     = userRoleRepository.GetRoleByUserName(userId).IdDepartment;
                var filterDepartmentId = departmentRepository.GetDepartmentIdByName(userDepartment);


                floorItems = floorRepository.GetFloorByDepartmentId(filterDepartmentId);



                if (floorItems != null && floorItems.Count != 0)
                {
                    ViewBag.datafloors = floorItems;
                }
                else
                {
                    ViewBag.Message = "No floor space has been allocated for your department. Please contact your admin.";
                }

                BookingsModel bookingsModel = bookingRepository.GetBookingById(id);

                return(View("EditBooking", bookingsModel));
            }
            else
            {
                return(RedirectToAction("Contact", "Home"));
            }
        }
        public IActionResult Cancel(int movieId)
        {
            BookingsModel model = new BookingsModel();

            model.Cancel = manager.CancelUserBookings(movieId);
            return(RedirectToAction(nameof(Bookings)));
        }
Пример #12
0
        public IActionResult Select(int id)
        {
            BookingsModel model = new BookingsModel();

            model.SelectedMovies = manager.GetUserBookings(id);

            return(View(model));
        }
        public IActionResult Bookings(int?movieId)
        {
            BookingsModel model   = new BookingsModel();
            MoviesModel   moviesM = new MoviesModel();

            model.Movies = manager.GetUserBookings(movieId.Value);

            return(RedirectToAction(nameof(Bookings)));
        }
        public BookingsModel AddBooking(BookingsModel bookingModel)
        {
            if (bookingModel == null)
            {
                throw new ArgumentNullException(nameof(bookingModel));
            }

            return(_AddBooking(bookingModel));
        }
 public bool IsDuplicateBooking(BookingsModel booking)
 {
     if (GetIdenticalBooking(booking.BookingValidFrom, booking.BookingValidTo, booking.IdFloor, booking.IdBuilding, booking.BookedSeats) == null)
     {
         return(false);
     }
     else
     {
         return(true);
     }
 }
Пример #16
0
        public async Task <bool> UpdateBooking(string id, BookingsModel booking)
        {
            HttpClient client = new HttpClient();

            client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("bearer", Settings.AccessToken);
            var json     = JsonConvert.SerializeObject(booking);
            var content  = new StringContent(json, Encoding.UTF8, "application/json");
            var response = await client.PutAsync(UrlConstants.bookingsurl2 + id, content);

            return(response.IsSuccessStatusCode);
        }
Пример #17
0
        public BookingDetailsPage(BookingsModel model)
        {
            InitializeComponent();

            servicetypeLbl.Text       = model.ServiceType;
            servicedurationLbl.Text   = model.ServiceDuration.ToString() + " " + "hours";
            FirstcleaningdateLbl.Text = model.StartDate;
            LastcleaningdateLbl.Text  = model.EndDate;
            servicetimeLbl.Text       = model.ServiceTime;
            extradescriptionLbl.Text  = model.ExtraDescription;
            if (model.IsNeedIroning == true)
            {
                ironingLbl.Text = "Yes";
            }
            else
            {
                ironingLbl.Text = "No";
            }

            if (model.IsNeedCleaningMaterials == true)
            {
                cleaningmaterialLbl.Text = "Yes";
            }
            else
            {
                cleaningmaterialLbl.Text = "No";
            }

            TotalcostLbl.Text   = model.TotalCost + " " + "Naira";
            cityLbl.Text        = model.City;
            streetLbl.Text      = model.Street;
            housenumberLbl.Text = model.HomeNumber;
            directionLbl.Text   = model.DirectionsOrLandmarks;

            if (model.IsHavePets == true)
            {
                petsLbl.Text = "Yes";
            }
            else
            {
                petsLbl.Text = "No";
            }
            entryLbl.Text  = model.ModeOfEntry;
            methodLbl.Text = model.PaymentMethod;

            if (model.IsCompleted == true)
            {
                statusLbl.Text = "Completed";
            }
            else
            {
                statusLbl.Text = "Pending";
            }
        }
Пример #18
0
        public ActionResult BookSchedule()
        {
            var query = (from p in db.Schedules
                         where p.DepartureTime > DateTime.Now
                         select p).ToList();
            var model = new BookingsModel
            {
                Schedule = query
            };

            return(View(model));
        }
Пример #19
0
        // GET: Booking/Details/5
        public ActionResult Details(Guid id)
        {
            var userId = User.Identity.GetUserName();

            if (userRoleRepository.GetRoleByUserName(userId) != null)
            {
                BookingsModel bookingModel = bookingRepository.GetBookingById(id);
                return(View("DetailsBooking", bookingModel));
            }
            else
            {
                return(RedirectToAction("Contact", "Home"));
            }
        }
Пример #20
0
        /// <summary>
        /// Example of how to add a booking
        /// </summary>
        /// <param name="orgCode"></param>
        /// <param name="Event">The ID of the event you want to attach the booking to</param>
        /// <param name="space">This is the user-configurable space code the booking takes place in</param>
        /// <param name="startDate">This should be set to the start date of the booking </param>
        /// <param name="endDate">This should be set to the start time of the booking </param>
        /// <param name="startTime">This should be set to the end date of the booking </param>
        /// <param name="endTime">This should be set to the end time of the booking </param>
        public BookingsModel Add(string orgCode, int Event, string space, DateTime startDate, DateTime endDate, DateTime startTime, DateTime endTime)
        {
            var myBooking = new BookingsModel
            {
                OrganizationCode = orgCode,
                Event            = Event,
                Daily            = "Y", //Y or N
                Space            = space,
                StartTime        = startTime,
                StartDate        = startDate,
                EndTime          = endTime,
                EndDate          = endDate,
            };

            return(APIUtil.AddBookingWithoutConflictCheck(USISDKClient, myBooking));
        }
Пример #21
0
        public ActionResult MonthBooking()
        {
            currentShowingBooking = new BookingsModel()
            {
                Bookings = this.scheduleService.GetMonthlyBookings()
            };

            if (snapshots.Snapshots == null)
            {
                snapshots.Snapshots = currentShowingBooking.Bookings.Select(x => new BookingSnapshot()
                {
                    Id = x.Id, BookStatus = x.BookStatus, End = x.End, IsInternal = x.IsInternal, Priority = x.Priority, Room = x.Room, Start = x.Start, User = x.User, Booking = x
                }).ToList();
            }

            return(View(currentShowingBooking));
        }
Пример #22
0
        public UpdateBookingPage(BookingsModel model)
        {
            InitializeComponent();
            if (model.IsCompleted == true)
            {
                infoLbl.IsVisible   = true;
                infoLbl.Text        = "This Booking is already marked complete and cannot be updated";
                MainSL.IsEnabled    = false;
                updateBtn.IsEnabled = false;
            }
            BookingSettings.BookingId = model.BookingId;
            CleanerSettings.CleanerId = model.CleanerId;
            startdatepicker.Date      = Convert.ToDateTime(model.StartDate);

            if (model.EndDate == "")
            {
                enddatepicker.Date = DateTime.Now.Date;
            }
            else
            {
                enddatepicker.Date = Convert.ToDateTime(model.EndDate);
            }


            DescriptionEditor.Text    = model.ExtraDescription;
            ironingswitch.IsToggled   = model.IsNeedIroning;
            materialsswitch.IsToggled = model.IsNeedCleaningMaterials;
            totalcostLbl.Text         = model.TotalCost;
            VATcostLbl.Text           = (Convert.ToInt32(totalcostLbl.Text) * 0.1).ToString();
            streetentry.Text          = model.Street;
            housenumberentry.Text     = model.HomeNumber;
            directionsentry.Text      = model.DirectionsOrLandmarks;
            petsswitch.IsToggled      = model.IsHavePets;
            detailseditor.Text        = model.ModeOfEntry;



            PopulatePicker();
            PopulateTimePicker();
            ironingswitch.Toggled   += Ironswitch;
            materialsswitch.Toggled += materialsswitch_Toggled;
            PopulateCityPicker();
            PopulateMethodPicker();
        }
        public void UpdateBooking(BookingsModel booking)
        {
            Booking bookingDb = dbContext.Bookings.FirstOrDefault(x => x.IdBooking == booking.IdBooking);

            if (bookingDb != null)
            {
                bookingDb.IdBooking        = booking.IdBooking;
                bookingDb.BookingValidFrom = booking.BookingValidFrom;
                bookingDb.BookingValidTo   = booking.BookingValidTo;
                bookingDb.BookingTimeStamp = booking.BookingTimeStamp;
                bookingDb.BookedSeats      = booking.BookedSeats;
                bookingDb.IdFloor          = booking.IdFloor;
                bookingDb.IdBuilding       = booking.IdBuilding;
                bookingDb.UserName         = booking.UserName;
                bookingDb.UserDepartment   = booking.UserDepartment;
                bookingDb.UserRole         = booking.UserRole;
                dbContext.SubmitChanges();
            }
        }
Пример #24
0
        public ActionResult Delete(Guid id)
        {
            var userId = User.Identity.GetUserName();

            if (userRoleRepository.GetRoleByUserName(userId) != null)
            {
                var userRole           = userRoleRepository.GetRoleByUserName(userId).IdUserType;
                var userDepartment     = userRoleRepository.GetRoleByUserName(userId).IdDepartment;
                var filterDepartmentId = departmentRepository.GetDepartmentIdByName(userDepartment);

                BookingsModel bookingModel = bookingRepository.GetBookingById(id);

                return(View("DeleteBooking", bookingModel));
            }
            else
            {
                return(RedirectToAction("Contact", "Home"));
            }
        }
Пример #25
0
        public ActionResult BookingDetail(int id)
        {
            var booking = BookingsManager.Find(id);

            var a = new BookingsModel
            {
                BookingId     = booking.BookingId,
                BookingNo     = booking.BookingNo,
                PkgStartDate  = booking.Package.PkgStartDate,
                PkgEndDate    = booking.Package.PkgEndDate,
                TravelerCount = booking.TravelerCount,
                CustomerId    = booking.Customer.CustFirstName,
                TripTypeId    = booking.TripType.Ttname,
                PkgDesc       = booking.Package.PkgDesc,
                PackageId     = booking.Package.PkgName,
                Price         = Math.Round((decimal)(booking.Package.PkgBasePrice + booking.Package.PkgAgencyCommission), 0),
            };

            return(View(a));
        }
        private Booking MapModelToDbObject(BookingsModel booking)
        {
            Booking bookingDb = new Booking();

            if (booking != null)
            {
                bookingDb.IdBooking        = booking.IdBooking;
                bookingDb.BookingValidFrom = booking.BookingValidFrom;
                bookingDb.BookingValidTo   = booking.BookingValidFrom;
                bookingDb.BookingTimeStamp = booking.BookingTimeStamp;
                bookingDb.BookedSeats      = booking.BookedSeats;
                bookingDb.IdFloor          = booking.IdFloor;
                bookingDb.IdBuilding       = booking.IdBuilding;
                bookingDb.UserRole         = booking.UserRole;
                bookingDb.UserDepartment   = booking.UserDepartment;
                bookingDb.UserName         = booking.UserName;
                return(bookingDb);
            }

            return(null);
        }
        private BookingsModel MapDbObjectToModel(Booking dbBooking)
        {
            BookingsModel booking = new BookingsModel();

            if (dbBooking != null)
            {
                booking.IdBooking        = dbBooking.IdBooking;
                booking.BookingValidFrom = dbBooking.BookingValidFrom;
                booking.BookingValidTo   = dbBooking.BookingValidFrom;
                booking.BookingTimeStamp = dbBooking.BookingTimeStamp;
                booking.BookedSeats      = dbBooking.BookedSeats;
                booking.IdFloor          = dbBooking.IdFloor;
                booking.IdBuilding       = dbBooking.IdBuilding;
                booking.UserName         = dbBooking.UserName;
                booking.UserDepartment   = dbBooking.UserDepartment;
                booking.UserRole         = dbBooking.UserRole;
                return(booking);
            }

            return(null);
        }
Пример #28
0
        /// <summary>
        /// Example showing how to save multiple items of the same model at a time.
        /// </summary>
        /// <param name="bookingsModel1">This contains a standard BookingsModel object.  A partial model mith missing properties is allowed.</param>
        /// <param name="bulkOperation1">Contains "create" or "update"</param>
        /// <param name="bookingsModel2">This contains a standard BookingsModel object.  A partial model mith missing properties is allowed.</param>
        /// <param name="bulkOperation2">Contains "create" or "update"</param>
        /// <param name="continueOnError">The bulk process is transactional and will save nothing if an item errors.  If you are submitting a list of unrelated items to save, set this as false and the bulk save process will attempt to continue saving if an item fails to save.  Note that certain errors will always result in the bulk operation halting.</param>
        /// <returns></returns>
        public BulkResponseModel Bulk(BookingsModel bookingsModel1, string bulkOperation1, BookingsModel bookingsModel2, string bulkOperation2, bool continueOnError, bool skipBookingConflicts)
        {
            /* If one item fails, you have the option to continue without it (see BulkRequestModel.ContinueOnError).  Use this for large updates of unrelated items.
             *  -You can track items via the BulkItemIndex tracker.*/

            var myBulkRequest = new BulkRequestModel
            {
                ContinueOnError = continueOnError
            };

            var mybulkRequestItem = new BulkRequestItem()
            {
                UngerboeckModel = bookingsModel1, //This is a standard Ungerboeck Model found in our SDK
                Action          = bulkOperation1, //contains "create" or "update".  Every item action can be independent.
                BulkItemIndex   = 1               //Use this index to track items in the response.  Whether an item succeeds or fails, it will preserve the index you assign it.
            };

            myBulkRequest.BulkRequestItems.Add(mybulkRequestItem);

            mybulkRequestItem = new BulkRequestItem()
            {
                UngerboeckModel = bookingsModel2,
                Action          = bulkOperation2,
                BulkItemIndex   = 2
            };

            myBulkRequest.BulkRequestItems.Add(mybulkRequestItem);

            if (skipBookingConflicts)
            {
                //Use this header to skip booking conflicts
                if (!USISDKClient.DefaultRequestHeaders.Contains("X-ValidationOverrides"))
                {
                    USISDKClient.DefaultRequestHeaders.Add("X-ValidationOverrides", "[{\"Code\": 12015}]");
                }
            }


            return(APIUtil.DoBulk <BookingsModel>(USISDKClient, myBulkRequest));
        }
Пример #29
0
        public List <BookingsModel> LKU_Bookings_MTY()
        {
            List <BookingsModel> lst = new List <BookingsModel>();

            SqlCommand    cmd = new SqlCommand();
            SqlDataReader rdr = default(SqlDataReader);

            SqlConnection conn = new SqlConnection(STRATIXDataConnString);

            using (conn)
            {
                conn.Open();

                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "SCORE_LKU_proc_Bookings_MTY";
                cmd.Connection  = conn;

                rdr = cmd.ExecuteReader();

                using (rdr)
                {
                    while (rdr.Read())
                    {
                        BookingsModel r = new BookingsModel();

                        r.workDy = (int)rdr["WORK_DY"];
                        r.prodDt = (int)rdr["WORK_DY"];
                        r.swDly  = (int)rdr["SW_DLY"];
                        r.msDly  = (int)rdr["MS_DLY"];
                        r.swAve  = (int)rdr["SW_AVE"];
                        r.msAve  = (int)rdr["MS_AVE"];

                        lst.Add(r);
                    }
                }
            }
            return(lst);
        }
Пример #30
0
        public ActionResult <BookingsModel> Get(string id)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(id))
                {
                    return(new StatusCodeResult((int)HttpStatusCode.BadRequest));
                }

                int.TryParse(id, out int Id);
                BookingsModel bookingsModel = _bookingsService.GetBookingDetailsById(Id);
                return(Ok(bookingsModel));
            }
            catch (ArgumentNullException ane)
            {
                return(BadRequest(ane.Message));
            }
            catch (Exception ex)
            {
                _logger?.LogCritical("There was an error on '{0}' invocation: {1}", nameof(Get), ex);
                return(new StatusCodeResult((int)HttpStatusCode.InternalServerError));
            }
        }