Beispiel #1
0
        public AllTasks GetAllArchivedTasksById(string currentUserId)
        {
            AllTasks allTasks = new AllTasks();

            using (var db = new TaskModelEntities())
            {
                var query = db.Tasks.Where(x => x.IsCompleted == true);
                var tasks = query.OrderBy(x => x.DueDate).ToList();

                foreach (var task in tasks)
                {
                    if (task.IsCompleted && task.UserId == currentUserId)
                    {
                        allTasks.Tasks.Add(new TaskModel()
                        {
                            Name             = task.Name,
                            DateCompleted    = task.DateCompleted,
                            DateStart        = task.DateStart,
                            Description      = task.Description,
                            DueDate          = task.DueDate,
                            EstimateDuration = int.Parse(task.EstimatedDuration),
                            IsCompleted      = task.IsCompleted,
                            Tags             = new List <string>()
                            {
                                task.Tag1, task.Tag2, task.Tag3
                            },
                            TaskId    = task.id,
                            TaskValue = task.TaskValue
                        });
                    }
                }
            }

            return(allTasks);
        }
Beispiel #2
0
        public void EditTaskById(int id, TaskModel model)
        {
            using (var db = new TaskModelEntities())
            {
                TaskModelDAL.Task taskToEdit = new TaskModelDAL.Task()
                {
                    Name              = model.Name,
                    DateCompleted     = model.DateCompleted,
                    DateStart         = model.DateStart,
                    Description       = model.Description,
                    DueDate           = model.DueDate,
                    EstimatedDuration = model.EstimateDuration.ToString(),
                    id          = holderID,
                    IsCompleted = model.IsCompleted,
                    Tag1        = model.Tags[0],
                    Tag2        = model.Tags[1],
                    Tag3        = model.Tags[2]
                };

                DeleteTaskById(model.TaskId);

                db.Tasks.Add(taskToEdit);

                db.SaveChanges();
            }
        }
Beispiel #3
0
        public void ArchiveTask(TaskModel model)
        {
            using (var db = new TaskModelEntities())
            {
                TaskModelDAL.Task taskToEdit = new TaskModelDAL.Task()
                {
                    Name              = model.Name,
                    DateCompleted     = DateTime.Now,
                    DateStart         = model.DateStart,
                    Description       = model.Description,
                    DueDate           = model.DueDate,
                    EstimatedDuration = model.EstimateDuration.ToString(),
                    id          = holderID,
                    IsCompleted = !model.IsCompleted,
                    TaskValue   = model.TaskValue,
                    Tag1        = model.Tags[0],
                    Tag2        = model.Tags[1],
                    Tag3        = model.Tags[2],
                    UserId      = model.UserId
                };

                DeleteTaskById(model.TaskId);

                db.Tasks.Add(taskToEdit);
                try
                {
                    db.SaveChanges();
                }
                catch (Exception e)
                {
                    string s = e.Message;
                }
            }
        }
Beispiel #4
0
        public void AddTask(TaskModel model)
        {
            using (var db = new TaskModelEntities())
            {
                var query = db.Tasks.Select(x => x);
                model.TaskId = query.Count();

                TaskModelDAL.Task taskToAdd = new TaskModelDAL.Task()
                {
                    Name              = model.Name,
                    DateCompleted     = model.DateCompleted,
                    DateStart         = DateTime.Now,
                    Description       = model.Description,
                    DueDate           = model.DueDate,
                    EstimatedDuration = model.EstimateDuration.ToString(),
                    id          = model.TaskId,
                    IsCompleted = false,
                    Tag1        = model.Tags[0],
                    Tag2        = "",
                    Tag3        = "",
                    TaskValue   = model.TaskValue,
                    UserId      = model.UserId
                };

                db.Tasks.Add(taskToAdd);

                db.SaveChanges();
            }
        }
Beispiel #5
0
        public AllTasks GetAllTasks()
        {
            AllTasks allTasks = new AllTasks();

            using (var db = new TaskModelEntities())
            {
                var query = db.Tasks.Select(x => x);
                var tasks = query.OrderBy(x => x.DueDate).ToList();

                foreach (var task in tasks)
                {
                    if (!task.IsCompleted)
                    {
                        allTasks.Tasks.Add(new TaskModel()
                        {
                            Name             = task.Name,
                            DateCompleted    = task.DateCompleted,
                            DateStart        = task.DateStart,
                            Description      = task.Description,
                            DueDate          = task.DueDate,
                            EstimateDuration = int.Parse(task.EstimatedDuration),
                            IsCompleted      = task.IsCompleted,
                            Tags             = new List <string>()
                            {
                                task.Tag1, task.Tag2, task.Tag3
                            },
                            TaskId = task.id
                        });
                    }
                }
            }
            return(allTasks);
        }
Beispiel #6
0
        public void DeleteTaskById(int id)
        {
            using (var db = new TaskModelEntities())
            {
                var task = db.Tasks.Where(x => x.id == holderID).First();
                db.Tasks.Remove(task);

                db.SaveChanges();
            }
        }
Beispiel #7
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public JsonResult IntegralInfo2(Guid teacherid, string xzqid, Guid schoolid)
        {
            TaskModelEntities task = new TaskModelEntities();

            //获取学分
            object[] paras = new SqlParameter[1];
            paras[0] = new SqlParameter("@UserID", teacherid);
            Decimal TotalScore = task.Database.SqlQuery <Decimal>(
                "select isnull(Sum(TaskScore),0) TotalScore from UCHome_UserIntergral where UserID=@UserID",
                paras).FirstOrDefault();

            //获取等级
            object[] paras2 = new SqlParameter[1];
            paras2[0] = new SqlParameter("@Scores", TotalScore);
            LevelInfo LevelInfo = task.Database.SqlQuery <LevelInfo>(
                "select min(pindex) Pindex,min(Scores) Score,min(pindex)+1 Lindex from UCHome_IntegralLevel where Scores>@Scores",
                paras2).FirstOrDefault();

            //积分排名
            object[] paras3 = new SqlParameter[1];
            paras3[0] = new SqlParameter("@UserID", teacherid);
            long citynum =
                task.Database.SqlQuery <long>(
                    "select Number from (select ROW_NUMBER() over(order by Sum(TaskScore) desc) Number,  UserID UserID,Sum(TaskScore) ACount from UCHome_UserIntergral a inner join Teacher_ZZJG0101 b on a.UserID=b.JSID  group by UserID) a where UserID=@UserID",
                    paras3).FirstOrDefault();

            //区级排名
            object[] paras4 = new SqlParameter[2];
            paras4[0] = new SqlParameter("@UserID", teacherid);
            paras4[1] = new SqlParameter("@AreaCode", xzqid);
            long areanum =
                task.Database.SqlQuery <long>(
                    "select Number from (select ROW_NUMBER() over(order by Sum(TaskScore) desc) Number,  UserID UserID,Sum(TaskScore) ACount from UCHome_UserIntergral a inner join Teacher_ZZJG0101 b on a.UserID=b.JSID inner join basic_zzxx0101 c on b.XXID=c.XXID where  c.XZQHM=@AreaCode  group by UserID) a where UserID=@UserID",
                    paras4).FirstOrDefault();

            //areanum = anos.Count(a => a.AreaCode == areacode && a.Number < citynum);
            //校级排名
            object[] paras5 = new SqlParameter[2];
            paras5[0] = new SqlParameter("@UserID", teacherid);
            paras5[1] = new SqlParameter("@XXID", schoolid);
            long schoolnum =
                task.Database.SqlQuery <long>(
                    "select Number from (select ROW_NUMBER() over(order by Sum(TaskScore) desc) Number,  UserID UserID,Sum(TaskScore) ACount from UCHome_UserIntergral a inner join Teacher_ZZJG0101 b on a.UserID=b.JSID where b.XXID=@XXID  group by UserID) a where UserID=@UserID",
                    paras5).FirstOrDefault();
            JsonResult jsonResult = new JsonResult
            {
                Data = new
                {
                    UserID     = teacherid,
                    TotalScore = TotalScore,
                    Level      = LevelInfo == null ? 1 : LevelInfo.Pindex,
                    LLevel     = LevelInfo == null ? 1 : LevelInfo.Lindex,
                    Score      = LevelInfo == null ? 1 : LevelInfo.Score,
                    CityNum    = citynum,
                    AreaNum    = areanum,
                    SchoolNum  = schoolnum,
                }
            };

            return(Json(jsonResult, JsonRequestBehavior.AllowGet));
        }