public async Task <IActionResult> OnPostAsync()
        {
            if (ModelState.IsValid)
            {
                int checkInTimeInt;
                int checkOutTimeInt;

                try
                {
                    checkInTimeInt  = int.Parse(CheckInTime.Split(":")[0]);
                    checkOutTimeInt = int.Parse(CheckOutTime.Split(":")[0]);
                }
                catch
                {
                    return(BadRequest());
                }

                if (checkInTimeInt <= checkOutTimeInt)
                {
                    ModelState.AddModelError("CheckInTime", "Check-in time must be later than check-out time!");

                    Accommodation = await accommodationLogic.GetAccommodationByIdAsync(AccommodationId);

                    Currencies = await currencyLogic.GetCurrenciesAsync();

                    return(Page());
                }

                var accommodationImagesFolderPath = Path.Combine(webHostEnviroment.WebRootPath, "accommodationPhotos");

                Accommodation = await accommodationLogic.GetAccommodationByIdAsync(AccommodationId);

                if (Accommodation.ApplicationUser.UserName != User.Identity.Name)
                {
                    return(Unauthorized());
                }

                var result = await accommodationLogic.UpdateAccommodationAsync(AccommodationId, Name, NumberOfBeds, PricePerNight, CurrencyId,
                                                                               RequireApproval, UserCanCancelBooking, CheckInTime, CheckOutTime,
                                                                               Accommodation.Name, accommodationImagesFolderPath);

                if (!result)
                {
                    return(BadRequest());
                }

                return(RedirectToPage("/Accommodations"));
            }

            return(BadRequest());
        }
        public async Task <IActionResult> OnPostAsync()
        {
            if (ModelState.IsValid)
            {
                int checkInTimeInt;
                int checkOutTimeInt;

                try
                {
                    checkInTimeInt  = int.Parse(CheckInTime.Split(":")[0]);
                    checkOutTimeInt = int.Parse(CheckOutTime.Split(":")[0]);
                }
                catch
                {
                    return(BadRequest());
                }
                if (checkInTimeInt <= checkOutTimeInt)
                {
                    ModelState.AddModelError("CheckInTime", "Check-in time must be later than check-out time!");
                    //this is required as the page requires accommodationTypes list populated in order to display the
                    //accommodation type select list and currency select list
                    AccommodationTypes = await AccommodationTypeLogic.GetAccommodationTypesAsync();

                    Currencies = await CurrencyLogic.GetCurrenciesAsync();

                    return(Page());
                }

                var accommodationPhotosRootFolder = Path.Combine(webHostEnvironment.WebRootPath, "accommodationPhotos");

                var result = await AccommodationLogic.CreateNewAccomodationAsync(Name, City, Address, NumberOfBeds, PricePerNight, CurrencyId, RequireApproval,
                                                                                 AccommodationTypeId, CheckInTime, CheckOutTime, User.Identity.Name, UserCanCancelBooking,
                                                                                 accommodationPhotosRootFolder, AccommodationHeaderPhoto, AccommodationPhotos);

                if (!result)
                {
                    return(BadRequest());
                }

                return(RedirectToPage("/Accommodations"));
            }
            else
            {
                return(BadRequest());
            }
        }
Esempio n. 3
0
        public JsonResult PostCheckIn(int id, string KeyCode)
        {
            var q = from kc in CurrentDatabase.CardIdentifiers
                    where KeyCode == kc.Id
                    select kc.PeopleId;
            var pid = q.SingleOrDefault();

            if (pid > 0)
            {
                var dt = Util.Now;
                var ck = new CheckInTime
                {
                    CheckInTimeX = dt,
                    PeopleId     = pid
                };
                CurrentDatabase.CheckInTimes.InsertOnSubmit(ck);
                CurrentDatabase.SubmitChanges();
            }
            return(Json(new { pid }));
        }
Esempio n. 4
0
        public JsonResult PostCheckIn(int id, string KeyCode)
        {
            Session["CheckInOrgId"] = id;
            var q = from kc in DbUtil.Db.CardIdentifiers
                    where KeyCode == kc.Id
                    select kc.PeopleId;
            var pid = q.SingleOrDefault();

            if (pid > 0)
            {
                var dt = Util.Now;
                var ck = new CheckInTime
                {
                    CheckInTimeX = dt,
                    PeopleId     = pid
                                   //KeyCode = KeyCode
                };
                DbUtil.Db.CheckInTimes.InsertOnSubmit(ck);
                DbUtil.Db.SubmitChanges();
            }
            return(Json(new { pid }));
        }
Esempio n. 5
0
        public ContentResult BuildingCheckin(int id, string location, int accesstype, int?guestof)
        {
            if (!Authenticate())
            {
                return(Content("not authorized"));
            }

            CheckInTime g = null;

            if (guestof != null)
            {
                g = (from e in DbUtil.Db.CheckInTimes
                     where e.Id == guestof
                     select e).FirstOrDefault();
            }

            var reader = new StreamReader(Request.InputStream);
            var s      = reader.ReadToEnd();

            if (!s.HasValue())
            {
                s = "<Activities />";
            }

            var xs         = new XmlSerializer(typeof(List <Activity>), new XmlRootAttribute("Activities"));
            var activities = xs.Deserialize(new StringReader(s)) as List <Activity>;

            var last = from e in DbUtil.Db.CheckInTimes
                       where e.PeopleId == id
                       where e.CheckInTimeX <= DateTime.Now
                       where e.CheckInTimeX >= DateTime.Now.AddHours(-1.5)
                       select e;

            if (guestof == null)
            {
                last = from f in last
                       where f.GuestOfId == null
                       select f;
            }
            else
            {
                last = from f in last
                       where f.GuestOfId == guestof
                       select f;
            }

            CheckInTime ac = null;

            if (last.Any())
            {
                ac = last.Single();

                foreach (var e in ac.CheckInActivities)
                {
                    DbUtil.Db.CheckInActivities.DeleteOnSubmit(e);
                }

                DbUtil.Db.SubmitChanges();

                foreach (var a in activities)
                {
                    ac.CheckInActivities.Add(new CheckInActivity {
                        Activity = a.Name
                    });
                }

                ac.AccessTypeID = accesstype;
            }
            else
            {
                ac = new CheckInTime
                {
                    PeopleId        = id,
                    Location        = location,
                    CheckInTimeX    = DateTime.Now,
                    GuestOfId       = guestof,
                    GuestOfPersonID = (g != null ? g.PeopleId ?? 0 : 0),
                    AccessTypeID    = accesstype
                };

                foreach (var a in activities)
                {
                    ac.CheckInActivities.Add(new CheckInActivity {
                        Activity = a.Name
                    });
                }

                DbUtil.Db.CheckInTimes.InsertOnSubmit(ac);
            }


            DbUtil.Db.SubmitChanges();

            foreach (var a in activities)
            {
                if (a.org > 0)
                {
                    Attend.RecordAttend(DbUtil.Db, id, a.org, true, DateTime.Today);
                }
            }

            return(Content(ac.Id.ToString()));
        }
Esempio n. 6
0
 /// <summary>已重载。</summary>
 public override String ToString() => $"[{UserId}]{CheckInType} {CheckInTime.ToDateTime().ToLocalTime().ToFullString()}";