예제 #1
0
        public ViewModels.Lessons.New SaveNew(FormCollection frm, int loggedInUserId)
        {
            var ret = new ViewModels.Lessons.New();

            // expect dd mm yyyy hh:mm tt
            var bkdt = (frm["BookingDate"] ?? "").Trim();

            if (string.IsNullOrEmpty(bkdt))
            {
                throw new Exception("Booking date is required.");
            }

            using (var conn = new dbEntities())
            {
                var description = (frm["Description"] ?? "").Trim();
                if (string.IsNullOrEmpty(description))
                {
                    throw new Exception("Description is required.");
                }

                if (Rules.Timezone.ConvertToUTC(Convert.ToDateTime(bkdt)) < DateTime.UtcNow)
                {
                    throw new Exception("Booking date not valid.");
                }

                var detailedDescription = (frm["DetailedDescription"] ?? "").Trim();
                detailedDescription = HttpUtility.UrlEncode(detailedDescription);

                // TokBox disabled for now
                //// note, relayed can't be archived (saved)
                //// when saving or archiving video, must be routed not relayed
                var tok          = new OpenTok(Constants.TokBox.ApiKey, Constants.TokBox.ApiSecret);
                var session      = tok.CreateSession("", MediaMode.RELAYED, ArchiveMode.MANUAL);
                var tokSessionId = session.Id;
                //string tokSessionId = null;

                ret.lesson = new Lesson()
                {
                    Account_ID          = loggedInUserId,
                    BookingDate         = Rules.Timezone.ConvertToUTC(Convert.ToDateTime(bkdt)),
                    DurationMins        = int.Parse(frm["DurationMins"]),
                    Description         = description,
                    DetailedDescription = detailedDescription,
                    ClassSize           = int.Parse(frm["ClassSize"]),
                    Subject             = (frm["Subject"] ?? "").Trim(),

                    TokBoxSessionId = tokSessionId,
                    ZoomStartUrl    = "",
                    ZoomJoinUrl     = ""
                };
                conn.Lessons.Add(ret.lesson);
                conn.SaveChanges();

                Rules.EventLogging.CreateLesson(loggedInUserId, ret.lesson);

                return(ret);
            }
        }
예제 #2
0
        public ViewModels.Lessons.New LoadNew(string date)
        {
            var ret = new ViewModels.Lessons.New();

            if (string.IsNullOrEmpty(date))
            {
                return(ret);
            }

            var bits = date.Split('-');

            if (bits.Length < 3)
            {
                return(ret);
            }

            ret.lesson.BookingDate = new DateTime(
                Convert.ToInt32(bits[0]), Convert.ToInt32(bits[1]), Convert.ToInt32(bits[2]), 9, 0, 0);

            return(ret);
        }