Beispiel #1
0
        public JsonResult EditBooking(int id)
        {
            int timeId = id;

            //Set time
            var now = preUni.getCurrentTime();

            string branchName;
            int    branchCode;

            using (NCBranch db = new NCBranch())
            {
                using (Db dbUser = new Db())
                {
                    var user = dbUser.Users.Find(User.Identity.Name);
                    branchCode = user.BranchCode;
                    branchName = user.BranchName;
                }
                var booking = db.Bookings.Where(x => x.BranchCode == branchCode).OrderByDescending(x => x.BookDate).FirstOrDefault();
                booking.UpdateDate = now;
                booking.ScanTimeID = id;
                db.SaveChanges();
                preUni.logging(User.Identity.Name, "Booking change : " + booking.BookDate + booking.ScanTimeID);
            }
            return(Json(new { success = true, message = "Booking changed", branchName = branchName }));
        }
Beispiel #2
0
        public JsonResult MakeBooking(int id)
        {
            int timeId = id;

            //Set time
            var now = preUni.getCurrentTime();

            //Get this friday(5)
            DayOfWeek desiredDay   = DayOfWeek.Friday;
            int       offsetAmount = (int)desiredDay - (int)DateTime.Now.DayOfWeek;
            var       bookDate     = new DateTime(now.Year, now.Month, now.Day).AddDays(offsetAmount);

            string branchName;

            using (NCBranch db = new NCBranch())
            {
                var booking = new BranchBookingDTO()
                {
                    ScanTimeID = timeId,
                    BookDate   = bookDate,
                    CreateDate = now,
                };
                using (Db dbUser = new Db()){
                    var user = dbUser.Users.Find(User.Identity.Name);
                    booking.BranchCode = user.BranchCode;
                    branchName         = user.BranchName;
                }
                if (booking.BranchCode == 4)
                {
                    return(Json(new { success = false, message = "Only branch can book.", branchName = branchName }));
                }
                if (db.Bookings.Any(x => x.BookDate == bookDate && x.ScanTimeID == booking.ScanTimeID))
                {
                    return(Json(new { success = false, message = "This time is aready booked.", branchName = branchName }));
                }
                db.Bookings.Add(booking);
                preUni.logging(User.Identity.Name, "Booking : " + booking.BookDate + booking.ScanTimeID);
                db.SaveChanges();
            }
            return(Json(new { success = true, message = "Booking succeed.", branchName = branchName }));
        }