示例#1
0
        public ActionResult InputMultipleEdit(int id = 0)
        {
            using (var db = new XkSystem.Models.DbContext())
            {
                var vm            = new Models.PerformDataDay.InputMultipleEdit();
                var tbPerformItem = (from p in db.Table <Entity.tbPerformItem>()
                                     where p.Id == vm.PerformItemId &&
                                     p.IsSelect && p.IsMany
                                     select p).FirstOrDefault();

                if (tbPerformItem == null)
                {
                }
                else
                {
                    vm.PerformOptionList = PerformOptionController.SelectList(vm.PerformItemId);
                }
                if (id != 0)
                {
                    var tb = (from p in db.Table <Entity.tbPerformData>()
                              where p.Id == id
                              select new Dto.PerformDataDay.InputMultipleEdit
                    {
                        Id = p.Id,
                        PerformItemName = p.tbPerformItem.PerformItemName,
                        StudentCode = p.tbStudent.StudentCode,
                        StudentName = p.tbStudent.StudentName,
                        Score = p.Score,
                        PerformOptionId = p.tbPerformOption == null ? 0 : p.tbPerformOption.Id
                    }).FirstOrDefault();

                    if (tb != null)
                    {
                        vm.PerformInputMultipleEdit = tb;
                    }
                }
                else
                {
                    vm.PerformInputMultipleEdit.PerformItemName = db.Set <Entity.tbPerformItem>().Find(vm.PerformItemId).PerformItemName;
                    vm.PerformInputMultipleEdit.StudentName     = db.Set <Student.Entity.tbStudent>().Find(vm.StudentId).StudentName;
                }
                return(View(vm));
            }
        }
示例#2
0
        public ActionResult InputMultipleEdit(Models.PerformDataDay.InputMultipleEdit vm)
        {
            using (var db = new XkSystem.Models.DbContext())
            {
                var error = new List <string>();
                if (error.Count == decimal.Zero)
                {
                    var tbPerformItemFirst = (from p in db.Table <Entity.tbPerformItem>()
                                              where p.Id == vm.PerformItemId
                                              select p).FirstOrDefault();

                    if (tbPerformItemFirst == null)
                    {
                        return(Code.MvcHelper.Post(new List <string>()
                        {
                            $"【评价项目】不存在,请重试;"
                        }));
                    }
                    else
                    {
                        var tbOldSum = (from p in db.Table <Entity.tbPerformData>()
                                        where p.tbCourse.Id == vm.PerformCourseId &&
                                        p.tbPerformItem.Id == vm.PerformItemId &&
                                        p.tbStudent.Id == vm.StudentId
                                        select p.Score).ToList().Sum();

                        if (vm.PerformInputMultipleEdit.Id == 0)
                        {
                            var tb = new Entity.tbPerformData();
                            tb.InputDate       = DateTime.Now;
                            tb.Score           = vm.PerformInputMultipleEdit.Score;
                            tb.tbPerformItem   = db.Set <Entity.tbPerformItem>().Find(vm.PerformItemId);
                            tb.tbSysUser       = db.Set <Sys.Entity.tbSysUser>().Find(Code.Common.UserId);
                            tb.tbStudent       = db.Set <Student.Entity.tbStudent>().Find(vm.StudentId);
                            tb.tbCourse        = db.Set <Course.Entity.tbCourse>().Find(vm.PerformCourseId);
                            tb.tbPerformOption = db.Set <Entity.tbPerformOption>().Find(vm.PerformInputMultipleEdit.PerformOptionId);
                            if (tb.tbPerformOption != null)
                            {
                                tb.Score = tb.tbPerformOption.OptionValue;
                            }
                            var sumScore = tb.Score + tbOldSum;
                            if (sumScore > tbPerformItemFirst.ScoreMax.ConvertToDecimal())
                            {
                                return(Code.MvcHelper.Post(new List <string>()
                                {
                                    $"项目总分:{sumScore}累计达到上限{tbPerformItemFirst.ScoreMax},请重新输入分数;"
                                }));
                            }
                            db.Set <Entity.tbPerformData>().Add(tb);
                            if (db.SaveChanges() > decimal.Zero)
                            {
                                XkSystem.Areas.Sys.Controllers.SysUserLogController.Insert("新增学生多次表现分");
                            }
                        }
                        else
                        {
                            var tb = (from p in db.Table <Entity.tbPerformData>()
                                      where p.Id == vm.PerformInputMultipleEdit.Id
                                      select p).FirstOrDefault();
                            if (tb != null)
                            {
                                tb.Score           = vm.PerformInputMultipleEdit.Score;
                                tb.tbPerformItem   = db.Set <Entity.tbPerformItem>().Find(vm.PerformItemId);
                                tb.tbCourse        = db.Set <Course.Entity.tbCourse>().Find(vm.PerformCourseId);
                                tb.tbSysUser       = db.Set <Sys.Entity.tbSysUser>().Find(Code.Common.UserId);
                                tb.tbStudent       = db.Set <Student.Entity.tbStudent>().Find(vm.StudentId);
                                tb.tbPerformOption = db.Set <Entity.tbPerformOption>().Find(vm.PerformInputMultipleEdit.PerformOptionId);
                                if (tb.tbPerformOption != null)
                                {
                                    tb.Score = tb.tbPerformOption.OptionValue;
                                }
                                var sumScore = tb.Score + tbOldSum;
                                if (sumScore > tbPerformItemFirst.ScoreMax.ConvertToDecimal())
                                {
                                    return(Code.MvcHelper.Post(new List <string>()
                                    {
                                        $"项目总分:{sumScore}累计达到上限{tbPerformItemFirst.ScoreMax},请重新输入分数;"
                                    }));
                                }
                                if (db.SaveChanges() > 0)
                                {
                                    XkSystem.Areas.Sys.Controllers.SysUserLogController.Insert("修改学生多次表现分");
                                }
                            }
                            else
                            {
                                error.AddError(Resources.LocalizedText.MsgNotFound);
                            }
                        }

                        #region 保存总分
                        var oldTotalList = (from p in db.Table <Perform.Entity.tbPerformTotal>()
                                            where p.tbPerform.Id == vm.PerformId &&
                                            p.tbCourse.Id == vm.PerformCourseId &&
                                            p.tbStudent.Id == vm.StudentId &&
                                            p.tbStudent.IsDeleted == false &&
                                            p.tbCourse.IsDeleted == false &&
                                            p.tbPerform.IsDeleted == false
                                            select p).ToList();

                        foreach (var a in oldTotalList)
                        {
                            a.IsDeleted  = true;
                            a.UpdateTime = DateTime.Now;
                        }

                        var studentSumScoreList = (from p in db.Table <Entity.tbPerformData>()
                                                   where p.tbCourse.Id == vm.PerformCourseId &&
                                                   p.tbStudent.Id == vm.StudentId &&
                                                   p.tbPerformItem.tbPerformGroup.tbPerform.Id == vm.PerformId &&
                                                   p.tbPerformItem.IsMany == false &&
                                                   p.tbPerformItem.IsSelect == false
                                                   select new
                        {
                            score = p.Score,
                            rate = p.tbPerformItem.Rate
                        }).ToList();

                        var studentSumScore = 0m;
                        if (studentSumScoreList.Count > 0)
                        {
                            studentSumScore = studentSumScoreList.Select(d => d.score * d.rate / 100).Sum();
                        }

                        var studentSumDayScore = (from p in db.Table <Entity.tbPerformData>()
                                                  where p.tbCourse.Id == vm.PerformCourseId &&
                                                  p.tbStudent.Id == vm.StudentId &&
                                                  p.tbPerformItem.tbPerformGroup.tbPerform.Id == vm.PerformId &&
                                                  ((p.tbPerformItem.IsMany && p.tbPerformItem.IsSelect) || (p.tbPerformItem.IsMany && p.tbPerformItem.IsSelect == false))
                                                  select p.Score).Sum();

                        var tfTotal = new Perform.Entity.tbPerformTotal();
                        tfTotal.TotalScore = studentSumScore + studentSumDayScore;
                        tfTotal.tbPerform  = db.Set <Perform.Entity.tbPerform>().Find(vm.PerformId);
                        tfTotal.tbStudent  = db.Set <Student.Entity.tbStudent>().Find(vm.StudentId);
                        tfTotal.tbCourse   = db.Set <Course.Entity.tbCourse>().Find(vm.PerformCourseId);
                        db.Set <Perform.Entity.tbPerformTotal>().Add(tfTotal);
                        if (db.SaveChanges() > decimal.Zero)
                        {
                            XkSystem.Areas.Sys.Controllers.SysUserLogController.Insert("新增学习表现总分");
                        }
                        #endregion
                    }
                }
                return(Code.MvcHelper.Post(null, returnUrl: Url.Action("InputMultipleList", new
                {
                    PerformId = vm.PerformId,
                    StudentId = vm.StudentId,
                    PerformItemId = vm.PerformItemId,
                    PerformCourseId = vm.PerformCourseId
                })));
            }
        }