コード例 #1
0
        public ActionResult Login(LogOnModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                string ValidateNumber = (string)Session["ValidateNumber"];

                if (model.ValidateCode.Equals(ValidateNumber))
                {
                    Administrator admin = db.Admin.SingleOrDefault(e => e.Username.Equals(model.UserName) &&
                                                                   e.Password.Equals(model.Password));
                    if (admin == null)
                    {
                        ModelState.AddModelError("", "用户名或密码不正确,请重试!");
                    }
                    else
                    {
                        if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") &&
                            !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
                        {
                            return(Redirect(returnUrl));
                        }
                        else
                        {
                            return(RedirectToAction("Index", "Index"));
                        }
                    }
                }
                else
                {
                    ModelState.AddModelError("", "提供的图形验证码不正确。");
                }
            }
            // 如果我们进行到这一步时某个地方出错,则重新显示表单
            return(View(model));
        }
コード例 #2
0
 /// <summary>
 /// 保存或更新系统管理员
 /// </summary>
 /// <param name="admin">需保存或更新的系统管理员信息</param>
 /// <returns>是否保存或更新成功</returns>
 public bool SaveOrUpdate(Admin admin)
 {
     if (admin.ID==0)
     {
         db.Admin.Add(admin);
     }
     db.SaveChanges();
     return true;
 }
コード例 #3
0
 public JObject save(HttpRequest adminForm)
 {
     bool result = false;
     string msg  = "";
     if (adminForm != null)
     {
         string Username = adminForm["Username"];
         string admin_id = null;
         bool Flag = IsUsernameExist(Username, admin_id);
         if (Flag)
         {
             msg = "该用户名已存在,请重新输入!";
         }
         else
         {
             Admin admin = new Admin();
             byte Roletype = Convert.ToByte(adminForm["Roletype"]);
             byte Seescope = Convert.ToByte(adminForm["Seescope"]);
             base.CopyProperties(admin, adminForm);
             try
             {
                 admin.CommitTime = DateTime.Now;
                 admin.UpdateTime = DateTime.Now;
                 admin.LoginTimes = 1;
                 db.Admin.Add(admin); 
                 db.SaveChanges();
                 msg = "保存成功!";
                 result = true;
             }
             catch (Exception error)
             {
                 msg = "操作失败:"+error.Message+",请重试!";
                 result = true;
             }
         }
     }
     return new JObject(
         new JProperty("success", result),
         new JProperty("msg", msg)
     );
 }
コード例 #4
0
        public void Save()
        {
            Admin admin = new Admin();
            admin.Username = AdminOriginal;
            admin.Realname = AdminOriginal;
            admin.Department_ID = 1;
            admin.Password = Password;
            admin.LoginTimes = 0;
            admin.Seescope = EnumSeescope.All.ToString();
            admin.Roletype = EnumRoletype.Superadmin.ToString();
            admin.CommitTime = DateTime.Now;
            admin.UpdateTime = DateTime.Now;
            int ID=adminService.Save(admin);
            Console.WriteLine(admin.ID+","+ID);

            //Test 1
            Assert.IsNotNull(admin.ID);

            //Test 2
            Assert.AreEqual(admin.ID,ID);
        }
コード例 #5
0
        public void SaveAdmin()
        {
            Admin admin = new Admin();
            admin.Username = AdminOriginal;
            admin.Realname = AdminOriginal;
            admin.Department_ID = 1;
            admin.Password = Password;
            admin.Seescope = EnumSeescope.All.ToString();
            admin.Roletype = EnumRoletype.Superadmin.ToString();
            admin.LoginTimes = 0;
            admin.CommitTime = DateTime.Now;
            admin.UpdateTime = DateTime.Now;
            //admin.ID = Guid.NewGuid();
            db.Admin.Add(admin);
            db.SaveChanges();

            // Test 1
            Assert.IsNotNull(admin.ID);

            //Test 2
            var newPersonFound = db.Admin.FirstOrDefault(
                person => person.Username == AdminOriginal);
            Assert.IsNotNull(newPersonFound);
        }
コード例 #6
0
        /// <summary>
        /// 导入:系统管理员
        /// </summary>
        public static JObject importAdmin(string fileName)
        {
            //Excel导出入到DataTable
            DataTable dt = UtilExcelOle.ExcelToDataTableBySheet(fileName,"Admin");
            if (dt != null)
            {
                Dictionary<string, string> dic = new Dictionary<string, string>()
                {
                    {"编号","ID"},
                    {"部门名称","Department_Name"},
                    {"用户名称","Username"},
                    {"密码","Password"},
                    {"真实姓名","Realname"},
                    {"扮演角色","RoletypeShow"},
                    {"视野","SeescopeShow"},
                    {"登录次数","LoginTimes"},
                    {"创建时间","CommitTime"},
                    {"更新时间","UpdateTime"}
                };

                UtilDataTable.ReplaceColumnName(dt, dic);

                //检查Excel中是否有用户名重复数据
                if (UtilDataTable.HasRepeat(dt, "Username"))
                {
                    Console.WriteLine("Excel中有重复用户名");
                    return new JObject(
                        new JProperty("success", true),
                        new JProperty("data", false)
                    );
                }
                //循环插入数据
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    Admin admin = new Admin();
                    UtilDataTable.ToObject(admin, dt.Rows[i], dt.Columns);
                    Department dep = db.Department.Where(e => e.Department_Name.Equals(admin.Department_Name)).SingleOrDefault();
                    admin.Department_ID = dep.ID;
                    admin.Seescope = EnumSeescope.SeescopeByShow(admin.SeescopeShow);
                    admin.Roletype = EnumRoletype.RoletypeByShow(admin.RoletypeShow);
                    db.Admin.Add(admin);
                }
                db.SaveChanges();
            }
            return new JObject(
                new JProperty("success", true),
                new JProperty("data",true)
            );
        }
コード例 #7
0
        public void importAdmin()
        {
            string fileName = "admin20140611084350.xls";
            fileName = Path.Combine(Gc.UploadPath, "attachment", "admin", fileName);
            //Excel导出入到DataTable
            DataTable dt = UtilExcelNpoi.ExcelToDataTable(fileName);
            if (dt!=null)
            {
                Dictionary<string, string> dic = new Dictionary<string, string>()
                {
                    {"编号","ID"},
                    {"部门名称","Department_Name"},
                    {"用户名称","Username"},
                    {"密码","Password"},
                    {"真实姓名","Realname"},
                    {"扮演角色","RoletypeShow"},
                    {"视野","SeescopeShow"},
                    {"登录次数","LoginTimes"},
                    {"创建时间","CommitTime"},
                    {"更新时间","UpdateTime"}
                };

                UtilDataTable.ReplaceColumnName(dt, dic);

                //检查数据格式是否正确
                //1、检查Excel中是否有用户名重复数据
                if (UtilDataTable.HasRepeat(dt, "Username"))
                {
                    Console.WriteLine("Excel中有重复用户名");
                    return;
                }
                //2、检查Excel中用户名是否存在与数据中相同数据
                List<Admin> admins = db.Admin.ToList();
                DataTable tableDt = UtilDataTable.ToDataTable<Admin>(admins);
                if (UtilDataTable.HasRepeat(tableDt, dt, "Username"))
                {
                    Console.WriteLine("Excel中与数据库有重复用户名");
                    return;
                }
                //循环插入数据
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    Admin admin = new Admin();
                    UtilDataTable.ToObject(admin,dt.Rows[i], dt.Columns);
                    Department dep = db.Department.Where(e=>e.Department_Name.Equals(admin.Department_Name)).SingleOrDefault();
                    admin.Department_ID = dep.ID;
                    admin.Seescope = EnumSeescope.SeescopeByShow(admin.SeescopeShow);
                    admin.Roletype = EnumRoletype.RoletypeByShow(admin.RoletypeShow);
                    //admin.CommitTime = DateTime.Now;
                    //admin.UpdateTime = DateTime.Now;
                    db.Admin.Add(admin);
                }
                db.SaveChanges();
            }
        }
コード例 #8
0
 /// <summary>
 /// 删除系统管理员
 /// </summary>
 /// <param name="admin">需要删除的系统管理员信息</param>
 /// <returns>是否删除成功</returns>
 public bool Delete(Admin admin)
 {
     db.Admin.Remove(admin);
     db.SaveChanges();
     return true;
 }
コード例 #9
0
 /// <summary>
 /// 更新系统管理员
 /// </summary>
 /// <param name="admin">需要更新的系统管理员信息</param>
 /// <returns>是否保存成功</returns>
 public bool Update(Admin admin)
 {
     db.SaveChanges();
     return true;
 }
コード例 #10
0
 /// <summary>
 /// 保存系统管理员
 /// </summary>
 /// <param name="admin">需要保存的系统管理员信息</param>
 /// <returns></returns>
 public int Save(Admin admin)
 {
     db.Admin.Add(admin);
     db.SaveChanges();
     return (int) admin.ID;
 }
コード例 #11
0
 public void InsertAdmin()
 {
     int CountInsert = 1000;
     //先默认插入CountInsert条Admin记录
     Admin admin = new Admin();
     int Count = db.Admin.Count();
     for (int i = 0; i < CountInsert; i++)
     {
         admin = new Admin();
         admin.Username = AdminOriginal + i;
         admin.Realname = AdminOriginal + i;
         admin.Department_ID = 1;
         admin.Password = Password;
         admin.LoginTimes = i;
         admin.Seescope = EnumSeescope.All.ToString();
         admin.Roletype = EnumRoletype.Superadmin.ToString();
         admin.CommitTime = DateTime.Now;
         admin.UpdateTime = DateTime.Now;
         db.Admin.Add(admin);
     }
     db.SaveChanges();
     Assert.IsTrue(Count == db.Admin.Count() - CountInsert);
 }
コード例 #12
0
        public void SaveOrUpdate()
        {
            Admin admin = new Admin();
            admin.Username = AdminOriginal;
            admin.Realname = AdminOriginal;
            admin.Department_ID = 1;
            admin.Password = Password;
            admin.LoginTimes = 0;
            bool IsSaved = adminService.SaveOrUpdate(admin);
            Assert.IsTrue(IsSaved);

            if (admin != null) admin.Username = AdminNameUpdated;
            admin.LoginTimes += 1;
            bool IsUpdated = adminService.SaveOrUpdate(admin);
            Assert.IsTrue(IsUpdated);
        }
コード例 #13
0
        public void InsertAdmin()
        {
            //先默认插入10条Admin记录
            int ID = 4;
            Admin admin;
            for (int i = 0; i < 1000; i++)
            {
                admin = new Admin();
                admin.Username = AdminOriginal + i;
                admin.Realname = AdminOriginal + i;
                admin.Department_ID = 1;
                admin.Password = Password;
                admin.LoginTimes = i;
                admin.Seescope = EnumSeescope.All.ToString();
                admin.Roletype = EnumRoletype.Superadmin.ToString();
                admin.CommitTime = DateTime.Now;
                admin.UpdateTime = DateTime.Now;
                ID = adminService.Save(admin);
            }
            Assert.IsTrue(ID>999);

        }