Esempio n. 1
0
        public JsonResult RemoveTimeslot(int id, Texxtoor.DataModels.Models.Users.UserProfile.AvailabilityFrame frame)
        {
            var profile = UserProfileManager.Instance.GetProfile(id);
            var slot    = profile.Availabilities.SingleOrDefault(a => a.StartAvailability == frame.StartAvailability && a.EndAvailability == frame.EndAvailability);

            if (slot != null)
            {
                profile.Availabilities.Remove(slot);
                UserProfileManager.Instance.SaveChanges();
                return(Json(new { msg = "OK", err = false }));
            }
            else
            {
                return(Json(new { msg = "Slot not found. Please check date values.", err = true }));
            }
        }
Esempio n. 2
0
        public JsonResult AddTimeslot(int id, Texxtoor.DataModels.Models.Users.UserProfile.AvailabilityFrame frame)
        {
            var profile = UserProfileManager.Instance.GetProfile(id);

            if (frame.StartAvailability < DateTime.Today)
            {
                return(Json(new { msg = "Not allowed to set dates in the past", err = true }));
            }
            // exclusive only, because we can assume END > START, START AND END must be before START or after END existing
            var slots = !profile.FutureAvailabilities.All(f => frame.EndAvailability <f.StartAvailability || frame.StartAvailability> f.EndAvailability);

            if (!slots)
            {
                profile.Availabilities.Add(frame);
                UserProfileManager.Instance.SaveChanges();
                return(Json(new { msg = "OK", err = false }));
            }
            else
            {
                return(Json(new { msg = "The give space is already occupied, slot not saved", err = true }));
            }
        }