public string MakeReservation(Reservation resItem)
        {
            ReservationType rtype = ReservationType.GetType(resItem.Type);

            if (rtype == ReservationType.LTWeekly || rtype == ReservationType.LTWeeklyWorkHrs)
            {
                resItem.EndDate = resItem.StartDate.AddDays(7);
            }
            else if (rtype == ReservationType.LTMonthly || rtype == ReservationType.LTMonthlyWorkHrs)
            {
                resItem.EndDate = resItem.StartDate.AddDays(30);
            }
            else
            {
                resItem.EndDate = resItem.StartDate.AddDays(1);
            }

            resItem.EndDate = resItem.EndDate.AddSeconds(-1); // 12.59.59 PM Local time on the last day of reservation

            using (var context = new MobileServiceContext())
            {
                try
                {
                    ParkingLot parkingLot = context.ParkingLots.Find(resItem.LotId);

                    string sql = "SELECT COUNT(*) FROM Reservation rr WHERE rr.LotId = @lotid and @startDt <= rr.EndDate and @endDt >= rr.StartDate";

                    SqlParameter[] parms = new SqlParameter[]
                    {
                        new SqlParameter("@lotid", resItem.LotId),
                        new SqlParameter("@startDt", resItem.StartDate),
                        new SqlParameter("@endDt", resItem.EndDate),
                    };

                    int reserved = context.Database.SqlQuery <int>(sql, parms).FirstOrDefault();

                    if (reserved >= parkingLot.Capacity)
                    {
                        return("Parking not available for the selected date(s)");
                    }

                    PriceModel priceModel = context.PriceModels.Find(resItem.PriceModelId);
                    resItem.AdvancePaid = priceModel.GetAdvanceCharge(resItem.Type);

                    Utils.CreateStripeCharge(resItem.AdvancePaid.Value, parkingLot.Name, resItem.ConfNumAdvance);

                    parkingLot.Reserved++;
                    context.Reservations.Add(resItem);
                    context.SaveChanges();
                }
                catch (Exception ex)
                {
                    throw ServerUtils.BuildException(ex);
                }
            }

            return(null);
        }
        private void FinalizeCheckout(MobileServiceContext context, Reservation rItem, DateTimeOffset checkoutTime)
        {
            ReservationType rtype = ReservationType.GetType(rItem.Type);

            if (rtype == ReservationType.ST)
            {
                rItem.ActualCheckout = checkoutTime;
            }
            else
            {
                rItem.ActualCheckin = rItem.ActualCheckout = null;
            }

            context.SaveChanges();
        }
Beispiel #3
0
        public decimal GetAdvanceCharge(int type)
        {
            decimal?        rt;
            ReservationType rtype = ReservationType.GetType(type);

            if (rtype == ReservationType.ST)
            {
                rt = GetMinimumCharge();
            }
            else
            {
                rt = GetRateforType(rtype);
            }

            return(rt.Value);
        }
Beispiel #4
0
        public decimal GetTotalCharge(Reservation rItem, DateTimeOffset checkoutTime)
        {
            ReservationType rtype = ReservationType.GetType(rItem.Type);

            decimal charge = GetAdvanceCharge(rItem.Type);

            if (rtype == ReservationType.ST)
            {
                decimal totCharge = GetChargeforTime(rItem.ActualCheckin.Value, checkoutTime);
                if (totCharge > charge)
                {
                    charge = totCharge;
                }
            }
            else
            {
                if (checkoutTime > rItem.EndDate)
                {
                    charge += GetChargeforTime(rItem.EndDate, checkoutTime);
                }
            }

            return(charge);
        }
        public string Checkin(string resCode)
        {
            using (var context = new MobileServiceContext())
            {
                Reservation rItem = context.Reservations
                                    .Include(rr => rr.ParkingLot)
                                    .Where(rr => rr.Id == resCode)
                                    .FirstOrDefault();

                if (rItem == null)
                {
                    return($"Invalid Reservation code");
                }

                ParkingLot lot = rItem.ParkingLot;

                if (rItem.ActualCheckin != null)
                {
                    return(String.Format("This code was already used to check in at {0:t} on {0:d}", lot.ConvertToLocalTime(rItem.ActualCheckin.Value)));
                }

                ReservationType rtype   = ReservationType.GetType(rItem.Type);
                DateTime        timeNow = DateTime.UtcNow;

                if (rtype == ReservationType.ST && timeNow > rItem.ExpectedCheckin.Value.AddMinutes(15))
                {
                    return(String.Format("This code is only valid until {0:t} on {0:d}", lot.ConvertToLocalTime(rItem.ExpectedCheckin.Value)));
                }

                if (rtype != ReservationType.ST && (timeNow < rItem.StartDate || timeNow > rItem.EndDate))
                {
                    if (rtype == ReservationType.LTDaily || rtype == ReservationType.LTDailyWorkHrs)
                    {
                        return($"This code is only valid on {lot.ConvertToLocalTime(rItem.StartDate):d}");
                    }
                    else
                    {
                        return($"This code is only valid from {lot.ConvertToLocalTime(rItem.StartDate):d} to {lot.ConvertToLocalTime(rItem.EndDate):d}");
                    }
                }

                if (rtype == ReservationType.LTDailyWorkHrs || rtype == ReservationType.LTWeeklyWorkHrs || rtype == ReservationType.LTMonthlyWorkHrs)
                {
                    DateTime timeNowLocal = lot.ConvertToLocalTime(timeNow, TimeZoneInfo.Utc);

                    if (timeNowLocal.Hour >= rItem.ParkingLot.WorkHrsEnd)
                    {
                        return($"This code is not valid after {lot.WorkHrsEndText}");
                    }

                    if (timeNowLocal.DayOfWeek == DayOfWeek.Saturday || timeNowLocal.DayOfWeek == DayOfWeek.Sunday)
                    {
                        return($"This code is not valid on Weekends");
                    }
                }

                rItem.ActualCheckin = timeNow;
                context.SaveChanges();
            }

            return(null);
        }