コード例 #1
0
 /// <summary>
 /// This method convert a SchedulerReservations object to an APPOINTMENTS object.
 /// </summary>
 /// <param name="reservation"></param>
 /// <returns></returns>
 private static APPOINTMENTS CreateAPPOINTMENTSobject(SchedulerReservations reservation)
 {
     return(new APPOINTMENTS()
     {
         CategoryName = reservation.CategoryName,
         StartDate = reservation.Start,
         EndDate = reservation.End,
         NickName = reservation.NickName,
         CurrentPrice = reservation.CurrentPrice,
         ReservationDate = reservation.ReservationDate,
         ID = reservation.TaskID
     });
 }
コード例 #2
0
        /// <summary>
        /// I check the overlapping in this method. (Two appointments cant cover each other.)
        /// </summary>
        /// <param name="appointment"></param>
        /// <returns></returns>
        private static bool CheckForOverlapping(SchedulerReservations appointment)
        {
            AppointmentBL           appBL           = new AppointmentBL();
            List <BOL.APPOINTMENTS> newappointments = appBL.GetAll().Where(x => x.StartDate > DateTime.Now).ToList();

            foreach (var item in newappointments)
            {
                if (item.StartDate <= appointment.End && appointment.Start <= item.EndDate)
                {
                    return(false);
                }
            }
            return(true);
        }
コード例 #3
0
        /// <summary>
        /// I use this method when a user wants to create a new appointment.
        /// </summary>
        /// <param name="appointment"></param>
        /// <returns></returns>
        public static SchedulerReservations DataConverter(SchedulerReservations appointment)
        {
            CategoryBL categBL = new CategoryBL();
            CATEGORIES categ   = categBL.GetByID(appointment.CategoryName);

            appointment.CurrentPrice    = (int)categ.Price;
            appointment.End             = appointment.Start.AddMinutes((int)categ.ProcessLengthInMunites);
            appointment.TaskID          = CalculateAppointmentID();
            appointment.ReservationDate = DateTime.Now;

            UserBL userBL = new UserBL();

            appointment.Title       = userBL.GetByID(appointment.NickName).FullName + ", " + categ.CategoryName;
            appointment.Description = appointment.Title + ", " + appointment.CurrentPrice + ", " + appointment.ReservationDate;

            return(appointment);
        }
コード例 #4
0
 /// <summary>
 /// I validate here the new appointment, and give message from the possible mistakes.
 /// </summary>
 /// <param name="appointment"></param>
 /// <returns></returns>
 public static string ReservationValidation(SchedulerReservations appointment)
 {
     if (appointment.CategoryName == null)
     {
         return("A foglalás sikertelen: Nincs kivaálsztva kategória!");
     }
     if (!CheckForOverlapping(appointment))
     {
         return("A foglalás sikertelen: Két időpont nem fedheti egymást!");
     }
     if (!ValidateAppointmentEnd(appointment))
     {
         return("A foglalás sikertelen: Az időpont nem fejeződhet be a munkaidő lejárta után!");
     }
     if (!ValidateAppointmentStart(appointment))
     {
         return("A foglalás sikertelen: Az aktuális időpontnál régebbi időpontot nem lehet lefoglalni!");
     }
     return(String.Empty);
 }
コード例 #5
0
        /// <summary>
        /// If a user create an appointment, I check the model first, then i check a few things. Form example,
        /// I check the overlapping, check the start, and end dates. If this method is returnd, i check the message: if the message is emtpty, then
        /// the appointment is valid, so I insert it to the database, else I give an alert message.
        /// </summary>
        /// <param name="request"></param>
        /// <param name="appointment"></param>
        /// <returns></returns>
        public virtual ActionResult Create([DataSourceRequest] DataSourceRequest request, SchedulerReservations appointment)
        {
            if (ModelState.IsValid)
            {
                appointment.NickName = User.Identity.Name;
                appointment          = ClassConverter.ClassConverter.DataConverter(appointment);

                string message = ClassConverter.ClassConverter.ReservationValidation(appointment);
                if (message == string.Empty)
                {
                    reservations.Add(appointment);
                    ClassConverter.ClassConverter.ConvertToInsertAppointment(appointment);
                }
                else
                {
                    appointment         = null;
                    TempData["Message"] = message;
                    ModelState.AddModelError("redirectNeeded", "The user needs to be redirected");
                    return(Json(reservations.ToDataSourceResult(request, ModelState)));
                }
            }
            return(Json(new[] { appointment }.ToDataSourceResult(request, ModelState)));
        }
コード例 #6
0
        public static void ConvertToInsertAppointment(SchedulerReservations reservation)
        {
            AppointmentBL bl = new AppointmentBL();

            bl.Insert(CreateAPPOINTMENTSobject(reservation));
        }
コード例 #7
0
        /// <summary>
        /// I check the new appointments start date here. (An appointment start date cant be earlier then the actual date.)
        /// </summary>
        /// <param name="appointment"></param>
        /// <returns></returns>
        private static bool ValidateAppointmentStart(SchedulerReservations appointment)
        {
            CategoryBL categBL = new CategoryBL();

            return(appointment.Start >= DateTime.Now);
        }
コード例 #8
0
        /// <summary>
        /// I check the new appointments end date here. (An appointment end date cant be later then 17 hour.)
        /// </summary>
        /// <param name="appointment"></param>
        /// <returns></returns>
        private static bool ValidateAppointmentEnd(SchedulerReservations appointment)
        {
            CategoryBL categBL = new CategoryBL();

            return(appointment.Start.AddMinutes((int)categBL.GetByID(appointment.CategoryName).ProcessLengthInMunites).Hour <= 17);
        }