public ActionResult btnNight_Click(FormCollection form)
        {
            string     teacherid = Session["UserID"].ToString();
            T_Deadline t_deadline;
            string     date     = form["dpNight"];
            string     time     = form["tpNight"];
            string     datetime = date + " " + time + ":00";
            DateTime   d_time   = Convert.ToDateTime(datetime);

            var night = from d in db.T_Deadline
                        where d.TypeID == type_night && d.TeacherID == teacherid
                        select d;

            if (night.Count() > 0)
            {
                t_deadline                 = night.First();
                t_deadline.Time            = d_time;
                db.Entry(t_deadline).State = EntityState.Modified;
            }
            else
            {
                t_deadline           = new T_Deadline();
                t_deadline.Time      = d_time;
                t_deadline.TypeID    = type_night;
                t_deadline.TeacherID = teacherid;

                db.T_Deadline.Add(t_deadline);
            }
            db.SaveChanges();

            Alert alert = new Alert();

            alert.Message     = "截止时间设置成功!";
            alert.EnableClose = false;
            alert.Show();

            return(UIHelper.Result());
        }
Ejemplo n.º 2
0
        public ActionResult btnSubmit_Click(FormCollection form, JArray first, JArray second, JArray third)
        {
            string teacherid  = Session["UserID"].ToString();
            string date       = form["dpDate"];
            string time_one   = form["tpFirst"];
            string time_two   = form["tpSecond"];
            string time_three = form["tpThird"];

            DateTime dt_one   = Convert.ToDateTime(date + " " + time_one + ":00");
            DateTime dt_two   = Convert.ToDateTime(date + " " + time_two + ":00");
            DateTime dt_three = Convert.ToDateTime(date + " " + time_three + ":00");

            T_Batch batch;
            T_Class t_class;
            Guid    id;

            #region 清除该辅导员管理的班级的批次信息
            var classes = from c in db.T_Class
                          where c.TeacherID == teacherid
                          select c;
            foreach (var item in classes)
            {
                item.Batch           = null;
                db.Entry(item).State = EntityState.Modified;
            }
            db.SaveChanges();
            #endregion

            #region 第一批
            if ((time_one != null) && (first.Count > 0))
            {
                batch = new T_Batch();

                var batch_id = from b in db.T_Batch
                               where b.Batch == 1 && b.TeacherID == teacherid
                               select b.ID;

                //辅导员是否设置过晚点名通知
                if (batch_id.Count() == 0)
                {
                    batch.ID        = Guid.NewGuid();
                    batch.Batch     = 1;
                    batch.TeacherID = teacherid;
                    batch.Datetime  = dt_one;
                    db.T_Batch.Add(batch);
                }
                else
                {
                    id                    = batch_id.ToList().First();
                    batch                 = db.T_Batch.Find(id);
                    batch.Datetime        = dt_one;
                    db.Entry(batch).State = EntityState.Modified;
                }
                db.SaveChanges();

                batch_id = from b in db.T_Batch
                           where b.Batch == 1 && b.TeacherID == teacherid
                           select b.ID;
                id = batch_id.ToList().First();
                foreach (JObject item in first)
                {
                    t_class                 = db.T_Class.Find(item["ID"].ToString());
                    t_class.Batch           = id;
                    db.Entry(t_class).State = EntityState.Modified;
                }
                db.SaveChanges();
            }
            #endregion

            #region 第二批
            if ((time_two != null) && (second.Count > 0))
            {
                batch = new T_Batch();
                var batch_id = from b in db.T_Batch
                               where b.Batch == 2 && b.TeacherID == teacherid
                               select b.ID;

                //辅导员是否设置过晚点名通知
                if (batch_id.Count() == 0)
                {
                    batch.ID        = Guid.NewGuid();
                    batch.Batch     = 2;
                    batch.TeacherID = teacherid;
                    batch.Datetime  = dt_two;
                    db.T_Batch.Add(batch);
                }
                else
                {
                    id                    = batch_id.ToList().First();
                    batch                 = db.T_Batch.Find(id);
                    batch.Datetime        = dt_two;
                    db.Entry(batch).State = EntityState.Modified;
                }
                try
                {
                    db.SaveChanges();
                }
                catch (DbEntityValidationException e)
                {
                }


                batch_id = from b in db.T_Batch
                           where b.Batch == 2 && b.TeacherID == teacherid
                           select b.ID;
                id = batch_id.ToList().First();
                foreach (JObject item in second)
                {
                    t_class                 = db.T_Class.Find(item["ID"].ToString());
                    t_class.Batch           = id;
                    db.Entry(t_class).State = EntityState.Modified;
                }
                db.SaveChanges();
            }
            #endregion

            #region 第三批
            if ((time_three != null) && (third.Count > 0))
            {
                batch = new T_Batch();
                var batch_id = from b in db.T_Batch
                               where b.Batch == 3 && b.TeacherID == teacherid
                               select b.ID;

                //辅导员是否设置过晚点名通知
                if (batch_id.Count() == 0)
                {
                    batch.ID        = Guid.NewGuid();
                    batch.Batch     = 3;
                    batch.TeacherID = teacherid;
                    batch.Datetime  = dt_three;
                    db.T_Batch.Add(batch);
                }
                else
                {
                    id                    = batch_id.ToList().First();
                    batch                 = db.T_Batch.Find(id);
                    batch.Datetime        = dt_three;
                    db.Entry(batch).State = EntityState.Modified;
                }
                db.SaveChanges();

                batch_id = from b in db.T_Batch
                           where b.Batch == 3 && b.TeacherID == teacherid
                           select b.ID;
                id = batch_id.ToList().First();
                foreach (JObject item in third)
                {
                    t_class                 = db.T_Class.Find(item["ID"].ToString());
                    t_class.Batch           = id;
                    db.Entry(t_class).State = EntityState.Modified;
                    db.SaveChanges();
                }
            }
            #endregion

            Alert alert = new Alert();
            alert.Message     = "晚点名通知设置成功";
            alert.EnableClose = false;
            alert.Show();
            return(UIHelper.Result());
        }