public JsonResult ClassInfoBaseUpdate(ClassInfoBaseUpdateInput input)
        {
            input.Id = GuserInfo.CurrentClass.Id;
            var result = _classInfoService.UpdateClassBaseInfo(GuserInfo.Id, input);

            result.Data = Mapper.Map <ClassInfoViewModel>(result.Data);
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Beispiel #2
0
        /// <summary>
        /// 跟新班级基本信息
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="input"></param>
        /// <returns></returns>
        public ResultBaseOutput UpdateClassBaseInfo(int userId, ClassInfoBaseUpdateInput input)
        {
            var result    = new ResultBaseOutput();
            var classInfo = _classDAL.GetModels(con => con.Id == input.Id).FirstOrDefault();

            if (classInfo is null)
            {
                result.Status = false;
                result.Msg    = "未找到班级信息!";
                return(result);
            }
            if (!string.IsNullOrEmpty(input.Introduce))
            {
                //修改描述
                classInfo.Introduce = input.Introduce;
            }
            if (!string.IsNullOrEmpty(input.ClassNotice))
            {
                //添加公告
                classInfo.ClassNotice.Add(new ClassNotice()
                {
                    CreateUser = classInfo.User.Where(con => con.Id == userId).FirstOrDefault(),
                    Notice     = input.ClassNotice
                });
            }
            if (input.qa != null && input.qa.Count == 3)
            {
                classInfo.ClassQustion = new List <ClassQuestion>();
                //问题&答案添加
                input.qa.ForEach(item =>
                                 classInfo.ClassQustion.Add(Mapper.Map <ClassQuestion>(item))
                                 );
            }
            try
            {
                _classDAL.SaveChanges();
                result.Status = true;
                result.Data   = classInfo;
            }
            catch (Exception ex)
            {
                result.Status = false;
                result.Msg    = "删除失败";
                result.Data   = ex;
            }
            return(result);
        }