Ejemplo n.º 1
0
 internal int DeleteScheduleItem(ScheduleItem scheduleItem)
 {
     if (scheduleItem.TaskId != null)
     {
         foreach (State state in db.Tasks.Find(scheduleItem.TaskId).States)
         {
             db.States.Remove(state);
         }
         var dir = Path.Combine(HttpRuntime.AppDomainAppPath, "/UploadedFiles/", db.Classes.Find(scheduleItem.ClassId).TaskPath, db.Tasks.Find(scheduleItem.TaskId).Code);
         Directory.Delete(dir);
         db.Tasks.Remove(db.Tasks.Find(scheduleItem.TaskId));
     }
     db.Schedule.Remove(scheduleItem);
     db.SaveChanges();
     return scheduleItem.ClassId;
 }
Ejemplo n.º 2
0
        internal ScheduleItem MakeTask(string taskName, string taskDescription, ScheduleItem scheduleItem, object adminId)
        {
            string code = taskName;
            Regex rgx = new Regex("[^a-zA-Z0-9 -]");
            code = rgx.Replace(code, "");
            TaskItem task = new TaskItem { Name = taskName, Description = taskDescription, Code = code, States = new List<State>() };
            
            foreach (User student in db.Classes.Find(scheduleItem.ClassId).Users.Where(u => !u.Roles.Equals(adminId)))
            {
                task.States.Add(new State(student.Id));
            }
            var dir = Path.Combine(HttpRuntime.AppDomainAppPath, "/UploadedFiles/", db.Classes.Find(scheduleItem.ClassId).TaskPath, task.Code);
            Directory.CreateDirectory(dir);
            db.Tasks.Add(task);
            db.SaveChanges();
            scheduleItem.TaskId = task.Id;

            return scheduleItem;
        }
Ejemplo n.º 3
0
        internal void CreateScheduleItem(FormCollection collection, object adminId)
        {
            int classId = int.Parse(collection.Get("classId"));
            DateTime startTime = DateTime.Parse(collection.Get("date") + " " + collection.Get("startTime"));
            DateTime stopTime = DateTime.Parse(collection.Get("date") + " " + collection.Get("stopTime"));

            ScheduleItem scheduleItem = new ScheduleItem { ClassId = classId, StartTime = startTime, StopTime = stopTime };
            if (collection.Get("task") == "on")
            {
                string taskName = collection.Get("taskName");
                string taskDescription = collection.Get("taskDescription");
                scheduleItem = MakeTask(taskName, taskDescription, scheduleItem, adminId);
            }
            db.Schedule.Add(scheduleItem);
            db.SaveChanges();
        }