Ejemplo n.º 1
0
        /// <summary>
        /// 添加实体信息,返回添加成功后的主键ID
        /// </summary>
        public int Insert(AdminDoRecord record)
        {
            int id = 0;

            const string sql = @"INSERT INTO AdminDoRecord(AdminID, AdminName, DoTime, DoName, DoContent, Remark)
                               VALUES (@AdminID, @AdminName, @DoTime, @DoName, @DoContent, @Remark);
                               SELECT LAST_INSERT_ID();";
            using (DbConnection connection = ConnectionManager.OpenConnection)
            {
                id = connection.Query<int>(sql, record).SingleOrDefault<int>();
            }
            return id;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 添加管理员操作记录
        /// </summary>
        public ServiceInvokeDTO AddAdminDoRecord(AdminDoRecord doRecord)
        {
            log.Debug(Constant.DEBUG_START);
            ServiceInvokeDTO result = null;
            try
            {
                adminDoRecordDAL.Insert(doRecord);
                result = new ServiceInvokeDTO(InvokeCode.SYS_INVOKE_SUCCESS);
            }
            catch (Exception ex)
            {
                // 记录异常但不抛出
                log.Error(ex);
            }
            log.Debug(Constant.DEBUG_END);

            return result;
        }
Ejemplo n.º 3
0
        public ActionResult AddAdmin()
        {
            log.Debug(Constant.DEBUG_START);

            string chineseName = ApiQueryUtil.QueryArgByPost("chinese_name");
            string phone = ApiQueryUtil.QueryArgByPost("phone");

            ServiceInvokeDTO result = null;
            try
            {
                AgencyAdmin admin = new AgencyAdmin();
                admin.AgencyID = (Session[Constant.SESSION_KEY_ADMIN] as AgencyAdminDTO).Agency.ID;
                admin.ChineseName = chineseName;
                admin.Phone = phone;
                admin.Level = AdminLevel.AgencyItemAdmin;

                result = agencyDataService.AddAdmin(admin);

                // Write admin do record.
                AgencyAdminDTO currentAdmin = Session[Constant.SESSION_KEY_ADMIN] as AgencyAdminDTO;
                if (result != null && result.Code == InvokeCode.SYS_INVOKE_SUCCESS)
                {
                    AdminDoRecord doRecord = new AdminDoRecord();
                    doRecord.AdminID = currentAdmin.ID;
                    doRecord.AdminName = currentAdmin.ChineseName;
                    doRecord.DoTime = DateTime.Now;
                    doRecord.DoName = DoActionType.AddAdmin.GetDescription();
                    doRecord.DoContent = string.Format("新管理员姓名:{0}", chineseName);
                    doRecord.Remark = string.Empty;
                    recordDataService.AddAdminDoRecord(doRecord);
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
                result = new ServiceInvokeDTO(InvokeCode.SYS_INNER_ERROR);
            }

            string json = JsonConvert.SerializeObject(result, Formatting.Indented, Constant.TIME_CONVERTER);
            log.Debug(Constant.DEBUG_END);

            return Content(json, Constant.JSON_MIME_TYPE);
        }
Ejemplo n.º 4
0
        public ActionResult DeleteMultiple()
        {
            log.Debug(Constant.DEBUG_START);

            string idString = ApiQueryUtil.QueryArgByPost("id");

            ServiceInvokeDTO result = null;
            try
            {
                int id = Convert.ToInt32(idString);

                AgencyAdminDTO currentAdmin = Session[Constant.SESSION_KEY_ADMIN] as AgencyAdminDTO;
                ServiceInvokeDTO checkResult = permissionService.CheckPermission(DoActionType.DeleteMultiple, currentAdmin.Agency.ID, id);
                if (checkResult.Code == InvokeCode.SYS_INVOKE_SUCCESS)
                {
                    result = itemDataService.DeleteMultiple(id);

                    // Write admin do record.
                    if (result != null && result.Code == InvokeCode.SYS_INVOKE_SUCCESS)
                    {
                        AdminDoRecord doRecord = new AdminDoRecord();
                        doRecord.AdminID = currentAdmin.ID;
                        doRecord.AdminName = currentAdmin.ChineseName;
                        doRecord.DoTime = DateTime.Now;
                        doRecord.DoName = DoActionType.DeleteMultiple.GetDescription();
                        doRecord.DoContent = string.Format("被删除的主键ID:{0}", idString);
                        doRecord.Remark = string.Empty;
                        recordDataService.AddAdminDoRecord(doRecord);
                    }
                }
                else
                {
                    result = checkResult;
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
                result = new ServiceInvokeDTO(InvokeCode.SYS_INNER_ERROR);
            }

            string json = JsonConvert.SerializeObject(result, Formatting.Indented, Constant.TIME_CONVERTER);
            log.Debug(Constant.DEBUG_END);

            return Content(json, Constant.JSON_MIME_TYPE);
        }
Ejemplo n.º 5
0
        public ActionResult DeleteJudgeInBatch()
        {
            log.Debug(Constant.DEBUG_START);

            string idListJson = ApiQueryUtil.QueryArgByPost("id_list");

            ServiceInvokeDTO result = null;
            try
            {
                List<int> idList = JsonConvert.DeserializeObject<List<int>>(idListJson);

                bool isRightPermission = false;
                AgencyAdminDTO currentAdmin = Session[Constant.SESSION_KEY_ADMIN] as AgencyAdminDTO;
                foreach (var id in idList)
                {
                    ServiceInvokeDTO checkResult = permissionService.CheckPermission(DoActionType.DeleteJudgeInBatch, currentAdmin.Agency.ID, id);
                    if (checkResult.Code == InvokeCode.SYS_INVOKE_SUCCESS)
                    {
                        isRightPermission = true;
                    }
                    else
                    {
                        isRightPermission = false;
                        break;
                    }
                }
                if (isRightPermission)
                {
                    result = itemDataService.DeleteJudge(idList);

                    // Write admin do record.
                    if (result != null && result.Code == InvokeCode.SYS_INVOKE_SUCCESS)
                    {
                        AdminDoRecord doRecord = new AdminDoRecord();
                        doRecord.AdminID = currentAdmin.ID;
                        doRecord.AdminName = currentAdmin.ChineseName;
                        doRecord.DoTime = DateTime.Now;
                        doRecord.DoName = DoActionType.DeleteJudgeInBatch.GetDescription();
                        doRecord.DoContent = string.Format("被删除的主键ID:{0}", idListJson);
                        doRecord.Remark = string.Empty;
                        recordDataService.AddAdminDoRecord(doRecord);
                    }
                }
                else
                {
                    result = new ServiceInvokeDTO(InvokeCode.PERMISSION_NOT_MINE_DATA_ERROR);
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
                result = new ServiceInvokeDTO(InvokeCode.SYS_INNER_ERROR);
            }

            string json = JsonConvert.SerializeObject(result, Formatting.Indented, Constant.TIME_CONVERTER);
            log.Debug(Constant.DEBUG_END);

            return Content(json, Constant.JSON_MIME_TYPE);
        }
Ejemplo n.º 6
0
        public ActionResult AddChapter()
        {
            log.Debug(Constant.DEBUG_START);

            string name = ApiQueryUtil.QueryArgByPost("name");

            ServiceInvokeDTO result = null;
            try
            {
                Chapter chapter = new Chapter();
                chapter.CourseID = (Session[Constant.SESSION_KEY_COURSE] as Course).ID;
                chapter.Name = name;

                result = itemDataService.AddChapter(chapter);

                // Write admin do record.
                if (result != null && result.Code == InvokeCode.SYS_INVOKE_SUCCESS)
                {
                    AgencyAdminDTO currentAdmin = Session[Constant.SESSION_KEY_ADMIN] as AgencyAdminDTO;

                    AdminDoRecord doRecord = new AdminDoRecord();
                    doRecord.AdminID = currentAdmin.ID;
                    doRecord.AdminName = currentAdmin.ChineseName;
                    doRecord.DoTime = DateTime.Now;
                    doRecord.DoName = DoActionType.AddChapter.GetDescription();
                    doRecord.DoContent = string.Format("新章节名称:{0}", name);
                    doRecord.Remark = string.Empty;
                    recordDataService.AddAdminDoRecord(doRecord);
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
                result = new ServiceInvokeDTO(InvokeCode.SYS_INNER_ERROR);
            }

            string json = JsonConvert.SerializeObject(result, Formatting.Indented, Constant.TIME_CONVERTER);
            log.Debug(Constant.DEBUG_END);

            return Content(json, Constant.JSON_MIME_TYPE);
        }
Ejemplo n.º 7
0
        public ActionResult AddSingle()
        {
            log.Debug(Constant.DEBUG_START);

            string isVipItemString = ApiQueryUtil.QueryArgByPost("is_vip_item");
            string chapterIDString = ApiQueryUtil.QueryArgByPost("chapter_id");

            string title = ApiQueryUtil.QueryArgByPost("title");
            HttpPostedFileBase imageFile = Request.Files["image"];
            string a = ApiQueryUtil.QueryArgByPost("a");
            string b = ApiQueryUtil.QueryArgByPost("b");
            string c = ApiQueryUtil.QueryArgByPost("c");
            string d = ApiQueryUtil.QueryArgByPost("d");
            string answer = ApiQueryUtil.QueryArgByPost("answer");
            string annotation = ApiQueryUtil.QueryArgByPost("annotation");
            string difficultyString = ApiQueryUtil.QueryArgByPost("difficulty");

            ServiceInvokeDTO result = null;
            try
            {
                SingleItem single = new SingleItem();
                single.AgencyID = (Session[Constant.SESSION_KEY_ADMIN] as AgencyAdminDTO).Agency.ID;
                single.IsVipItem = Convert.ToInt32(isVipItemString);
                single.ChapterID = Convert.ToInt32(chapterIDString);

                single.Title = title;
                single.A = a;
                single.B = b;
                single.C = c;
                single.D = d;
                single.Answer = answer;
                single.Annotation = annotation;
                single.Difficulty = Convert.ToInt32(difficultyString);
                single.AddPerson = (Session[Constant.SESSION_KEY_ADMIN] as AgencyAdminDTO).ChineseName;

                if (imageFile != null)
                {
                    byte[] imageBytes = null;
                    using (Stream inputStream = imageFile.InputStream)
                    {
                        MemoryStream memoryStream = inputStream as MemoryStream;
                        if (memoryStream == null)
                        {
                            memoryStream = new MemoryStream();
                            inputStream.CopyTo(memoryStream);
                        }
                        imageBytes = memoryStream.ToArray();
                    }
                    single.Image = imageBytes;
                }

                result = itemDataService.AddSingle(single);

                // Write admin do record.
                if (result != null && result.Code == InvokeCode.SYS_INVOKE_SUCCESS)
                {
                    AgencyAdminDTO currentAdmin = Session[Constant.SESSION_KEY_ADMIN] as AgencyAdminDTO;
                    AdminDoRecord doRecord = new AdminDoRecord();
                    doRecord.AdminID = currentAdmin.ID;
                    doRecord.AdminName = currentAdmin.ChineseName;
                    doRecord.DoTime = DateTime.Now;
                    doRecord.DoName = DoActionType.AddSingle.GetDescription();
                    doRecord.DoContent = string.Format("新单选题标题:{0}", title);
                    doRecord.Remark = string.Empty;
                    recordDataService.AddAdminDoRecord(doRecord);
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
                result = new ServiceInvokeDTO(InvokeCode.SYS_INNER_ERROR);
            }

            string json = JsonConvert.SerializeObject(result, Formatting.Indented, Constant.TIME_CONVERTER);
            log.Debug(Constant.DEBUG_END);

            return Content(json, Constant.JSON_MIME_TYPE);
        }
Ejemplo n.º 8
0
        public ActionResult StartLoadSingleExcelFile()
        {
            log.Debug(Constant.DEBUG_START);

            // 题库Excel文件
            string fileName = Request["file_name"];

            ServiceInvokeDTO result = null;
            try
            {
                if (!string.IsNullOrEmpty(fileName))
                {
                    string tempFilePath = Server.MapPath("/") + @"Files\TempData\" + fileName;

                    if (System.IO.File.Exists(tempFilePath))
                    {
                        // 1.处理数据并校验
                        Course currentCourse = (Course)Session[Constant.SESSION_KEY_COURSE];
                        AgencyAdminDTO currentUser = (AgencyAdminDTO)Session[Constant.SESSION_KEY_ADMIN];
                        List<SingleItem> singles = TemplateUtil.ReadSingleTemplate(currentUser, currentCourse.ID, tempFilePath, true);

                        // 2.批量添加
                        result = itemDataService.AddSingle(singles);

                        // 3.删除文件
                        System.IO.File.Delete(tempFilePath);

                        result = new ServiceInvokeDTO(InvokeCode.SYS_INVOKE_SUCCESS);

                        // Write admin do record.
                        if (result != null && result.Code == InvokeCode.SYS_INVOKE_SUCCESS)
                        {
                            AgencyAdminDTO currentAdmin = Session[Constant.SESSION_KEY_ADMIN] as AgencyAdminDTO;
                            AdminDoRecord doRecord = new AdminDoRecord();
                            doRecord.AdminID = currentAdmin.ID;
                            doRecord.AdminName = currentAdmin.ChineseName;
                            doRecord.DoTime = DateTime.Now;
                            doRecord.DoName = DoActionType.AddSingleInBatch.GetDescription();
                            doRecord.DoContent = string.Empty;
                            doRecord.Remark = string.Empty;
                            recordDataService.AddAdminDoRecord(doRecord);
                        }
                    }
                    else
                    {
                        result = new ServiceInvokeDTO(InvokeCode.ITEM_FILE_NOT_EXIST_ERROR);
                    }
                }
                else
                {
                    result = new ServiceInvokeDTO(InvokeCode.ITEM_FILE_FORMAT_ERROR);
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
                result = new ServiceInvokeDTO(InvokeCode.SYS_INNER_ERROR, ex.Message);

                // 删除文件
                if (!string.IsNullOrEmpty(fileName))
                {
                    string tempFilePath = Server.MapPath("/") + @"Files\TempData\" + fileName;
                    System.IO.File.Delete(tempFilePath);
                }
            }

            string json = JsonConvert.SerializeObject(result, Formatting.Indented, Constant.TIME_CONVERTER);
            log.Debug(Constant.DEBUG_END);

            return Content(json, Constant.JSON_MIME_TYPE);
        }
Ejemplo n.º 9
0
        public ActionResult UpdateAgencyNoticeConfig()
        {
            log.Debug(Constant.DEBUG_START);

            string notice = ApiQueryUtil.QueryArgByPost("notice");

            ServiceInvokeDTO result = null;
            try
            {
                AgencyAdminDTO currentAdmin = Session[Constant.SESSION_KEY_ADMIN] as AgencyAdminDTO;
                int agencyID = currentAdmin.Agency.ID;
                result = agencyDataService.UpdateAgencyNoticeConfig(agencyID, notice);

                // Write admin do record.
                if (result != null && result.Code == InvokeCode.SYS_INVOKE_SUCCESS)
                {
                    AdminDoRecord doRecord = new AdminDoRecord();
                    doRecord.AdminID = currentAdmin.ID;
                    doRecord.AdminName = currentAdmin.ChineseName;
                    doRecord.DoTime = DateTime.Now;
                    doRecord.DoName = DoActionType.UpdageAgencyConfig.GetDescription();
                    doRecord.DoContent = string.Format("修改通知公告为:{0}", notice);
                    doRecord.Remark = string.Empty;
                    recordDataService.AddAdminDoRecord(doRecord);
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
                result = new ServiceInvokeDTO(InvokeCode.SYS_INNER_ERROR);
            }

            string json = JsonConvert.SerializeObject(result, Formatting.Indented, Constant.TIME_CONVERTER);
            log.Debug(Constant.DEBUG_END);

            return Content(json, Constant.JSON_MIME_TYPE);
        }
Ejemplo n.º 10
0
        public ActionResult Logout()
        {
            log.Debug(Constant.DEBUG_START);

            try
            {
                // Remove session
                if (Session[Constant.SESSION_KEY_ADMIN] != null)
                {
                    // Write admin do record.
                    AgencyAdminDTO currentAdmin = Session[Constant.SESSION_KEY_ADMIN] as AgencyAdminDTO;
                    if (currentAdmin != null)
                    {
                        AdminDoRecord doRecord = new AdminDoRecord();
                        doRecord.AdminID = currentAdmin.ID;
                        doRecord.AdminName = currentAdmin.ChineseName;
                        doRecord.DoTime = DateTime.Now;
                        doRecord.DoName = DoActionType.Logout.GetDescription();
                        doRecord.DoContent = string.Empty;
                        doRecord.Remark = string.Empty;
                        recordDataService.AddAdminDoRecord(doRecord);
                    }

                    Session[Constant.SESSION_KEY_ADMIN] = null;
                }
                if (Session[Constant.SESSION_KEY_COURSE] != null)
                {
                    Session[Constant.SESSION_KEY_COURSE] = null;
                }
                return RedirectToAction("login", "home");
            }
            catch (Exception ex)
            {
                log.Error(ex);
                return View("~/Views/Shared/error.cshtml");
            }
        }
Ejemplo n.º 11
0
        public ActionResult LoginEx()
        {
            log.Debug(Constant.DEBUG_START);

            string userName = ApiQueryUtil.QueryArgByPost("user_name");
            string password = ApiQueryUtil.QueryArgByPost("pwd_hidden");

            try
            {
                // Write cookies
                HttpCookie cookie = Request.Cookies[Constant.COOKIE_NAME];
                if (cookie == null)
                {
                    cookie = new HttpCookie(Constant.COOKIE_NAME);
                    cookie.Expires = DateTime.Now.AddDays(Constant.COOKIE_EXPIRES_DAY);
                    cookie.Values.Add(Constant.COOKIE_KEY_USER_NAME, userName);
                    Response.Cookies.Add(cookie);
                }
                else
                {
                    cookie.Values[Constant.COOKIE_KEY_USER_NAME] = userName;
                    Response.Cookies.Set(cookie);
                }

                ServiceInvokeDTO<AgencyAdminDTO> loginResult = agencyDataService.AdminLogin(userName, password);
                if (loginResult != null && loginResult.Code == InvokeCode.SYS_INVOKE_SUCCESS)
                {
                    // Write session
                    Session[Constant.SESSION_KEY_ADMIN] = loginResult.Data;

                    int courseID = itemDataService.GetAgencyCourses(loginResult.Data.Agency.ID).Data[0].ID;
                    if (cookie != null && cookie[Constant.COOKIE_KEY_COURSE_ID] != null)
                    {
                        courseID = Convert.ToInt32(cookie[Constant.COOKIE_KEY_COURSE_ID]);
                    }
                    Session[Constant.SESSION_KEY_COURSE] = itemDataService.GetCourseByID(courseID).Data;

                    // Write admin do record.
                    AgencyAdminDTO currentAdmin = loginResult.Data;
                    if (currentAdmin != null)
                    {
                        AdminDoRecord doRecord = new AdminDoRecord();
                        doRecord.AdminID = currentAdmin.ID;
                        doRecord.AdminName = currentAdmin.ChineseName;
                        doRecord.DoTime = DateTime.Now;
                        doRecord.DoName = DoActionType.Login.GetDescription();
                        doRecord.DoContent = string.Empty;
                        doRecord.Remark = string.Empty;
                        recordDataService.AddAdminDoRecord(doRecord);
                    }

                    // To dashboard
                    if (loginResult.Data.Level == AdminLevel.AgencyCreatorAdmin)
                    {
                        return RedirectToAction("index", "agency");
                    }
                    else
                    {
                        return RedirectToAction("index", "item");
                    }
                }
                else
                {
                    //Pass result string to login action.
                    TempData[Constant.LOG_TIP_VIEW_AND_TEMP_KEY] = loginResult.Message;
                    return RedirectToAction("login", "home");
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
                return View("~/Views/Shared/error.cshtml");
            }
        }