コード例 #1
0
        //gat all admins
        public IList <AdministratorDal> GetAll()
        {
            List <AdministratorDal> list = new List <AdministratorDal>();
            string SqlCommand            = "Select_aLL_Administrator";

            using (SqlConnection con = new SqlConnection(ConnectionString))
            {
                SqlCommand cmd = new SqlCommand(SqlCommand, con);
                try
                {
                    cmd.Connection.Open();
                    cmd.CommandType = CommandType.StoredProcedure;
                    SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.Default);
                    while (reader.Read() == true)
                    {
                        AdministratorDal admin = new AdministratorDal();
                        admin._Id        = (int)reader["Id"];
                        admin._User_Name = (string)reader["User_Name"];
                        admin._Password  = (string)reader["Password "];
                        admin.First_Name = (string)reader["First_Name"];
                        admin.Last_Name  = (string)reader["Last_Name"];
                        admin.Email      = (string)reader["Email"];
                        list.Add(admin);
                    }
                    return(list);
                }catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    cmd.Connection.Close();
                }
            }
        }
コード例 #2
0
        public IActionResult JsonIndex()
        {
            var administratorDal  = new AdministratorDal();
            var administratorList = administratorDal.Query();
            var func = new Func <string, string>((administratorId) => {
                if (string.IsNullOrEmpty(administratorId))
                {
                    return(string.Empty);
                }
                var p = administratorList.SingleOrDefault(o => o.AdministratorId == administratorId);
                if (p == null)
                {
                    return(string.Empty);
                }
                return(p.Name);
            });
            var dal = new EmployeeGroupDal();

            var list    = dal.Query();
            var dtoList = mapper.Map <List <EmployeeGroupJsonIndexModel> >(list);

            dtoList.ForEach(o =>
            {
                o.MonitorName         = func(o.MonitorId);
                o.OtherEmployeesName1 = func(o.OtherEmployeesId1);
                o.OtherEmployeesName2 = func(o.OtherEmployeesId2);
            });
            return(Json(dtoList));
        }
コード例 #3
0
        public IActionResult JsonIndex(AdministratorJsonIndexModel model)
        {
            if (model.StationNo == "0")
            {
                model.StationNo = null;
            }


            var dal   = new AdministratorDal();
            var list  = dal.Query();
            var list2 = (from o in list
                         select new //AdministratorDefinition()
            {
                AdministratorId = o.AdministratorId,
                SysAdmin = o.SysAdmin ? "系统管理员" : "管理员",
                Name = o.Name,
                Accounts = o.Accounts,
                PassWord = o.PassWord,
                ReWritePassWord = o.ReWritePassWord,
                Phone = o.Phone,
                RoleId = o.RoleId,
            }).ToList();

            var grid = new
            {
                total = 0,
                rows  = list2,
            };

            return(Json(grid));
        }
コード例 #4
0
 public void createOneAdmin(LoginToken <AdministratorLogin> token, AdministratorDal admin)
 {
     if (token.User.GetAdministrator())
     {
         _administratorDAO.Add(admin);
     }
 }
コード例 #5
0
        // geting one admin
        public void Add(AdministratorDal t)
        {
            string SqlCommand = "Add_One_Administrator";

            using (SqlConnection con = new SqlConnection(ConnectionString))
            {
                SqlCommand cmd = new SqlCommand(SqlCommand, con);
                try
                {
                    cmd.Connection.Open();
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add(new SqlParameter(@"_User_Name", t._User_Name));
                    cmd.Parameters.Add(new SqlParameter(@"_Password", t._Password));
                    cmd.Parameters.Add(new SqlParameter(@"_First_Name", t.First_Name));
                    cmd.Parameters.Add(new SqlParameter(@"_Last_Name", t.Last_Name));
                    cmd.Parameters.Add(new SqlParameter(@"_Email", t.Email));
                    cmd.ExecuteNonQuery();
                    cmd.Connection.Close();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    cmd.Connection.Close();
                }
            }
        }
コード例 #6
0
        // delete admin from data dase
        public void Remove(AdministratorDal t)
        {
            string SqlCommand = "Remove_One_Administrator";

            using (SqlConnection con = new SqlConnection(ConnectionString))
            {
                SqlCommand cmd = new SqlCommand(SqlCommand, con);
                try
                {
                    cmd.Connection.Open();
                    cmd.Parameters.Add(new SqlParameter(@"id", t.GetHashCode()));
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.ExecuteNonQuery();
                    cmd.Connection.Close();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    cmd.Connection.Close();
                }
            }
        }
コード例 #7
0
        public IActionResult Update(string employeeGroupId)
        {
            var dal              = new EmployeeGroupDal();
            var p                = dal.Find(employeeGroupId);
            var model            = mapper.Map <EmployeeGroupUpdateModel>(p);
            var administratorDal = new AdministratorDal();

            model.Administrators = administratorDal.Query();
            return(View(model));
        }
コード例 #8
0
        public IActionResult Add()
        {
            var dal   = new AdministratorDal();
            var model = new EmployeeGroupAddModel()
            {
                Administrators = dal.Query(),
            };

            return(View(model));
        }
コード例 #9
0
        public IActionResult Index2()
        {
            var dal   = new AdministratorDal();
            var model = new HomeIndexModel()
            {
                Count = dal.Query().Count,
            };

            return(View(model));
        }
コード例 #10
0
        public IActionResult ChangePassword(FrameChangePassword model)
        {
            if (ModelState.IsValid)
            {
                var dal = new AdministratorDal();
                try
                {
                    CryptoHelper helper = new CryptoHelper();
                    var          p      = CurrentAdmin;
                    var          old    = dal.FindByAccounts(model.Accounts.Trim().ToLower());
                    if (old != null)
                    {
                        if (old.AdministratorId != p.AdministratorId)
                        {
                            ModelState.AddModelError("", "该账号已经被占用.");
                            return(View(model));
                        }
                    }

                    if (model.OldPassword.Trim() == helper.Decrypt(p.PassWord.Trim()))
                    {
                        var logMode = new LogDefinition()
                        {
                            Content        = "修改密码",
                            AdminName      = p.Name,
                            AfterUpdate    = "",
                            BeforeUpdate   = "",
                            UpdateDateTime = DateTime.Now,
                        };
                        var logDal = new LogDal();
                        logDal.Add(logMode);
                        p.PassWord = helper.Encrypt(model.NewPassword);
                        p.Accounts = model.Accounts.Trim().ToLower();
                        dal.Update(p);
                        CurrentAdmin = null;
                        return(RedirectToAction("LogOn", "Account"));
                    }
                    else
                    {
                        ModelState.AddModelError("", "密码不正确.");
                    }
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("", ex.Message);
                }
            }

            //model.OldPassword = "";
            //model.NewPassword = "";
            //model.ConfirmPassword = "";

            return(View(model));
        }
コード例 #11
0
        public IActionResult LogOn(AccountLogOnModel model)
        {
            if (ModelState.IsValid)
            {
                var administratorDal = new AdministratorDal();
                try
                {
                    var p = administratorDal.FindByAccounts(model.Accounts.ToLower());
                    if (p != null)
                    {
                        //Url.IsLocalUrl(returnUrl)
                        CryptoHelper helper = new CryptoHelper();
                        if (p.PassWord.Trim() == helper.Encrypt(model.Password))
                        {
                            Cache.SetString("CurrentAdmin", p.AdministratorId);
                            HttpContext.Session.SetString("CurrentAdmin", p.AdministratorId);
                            var logMode = new LogDefinition()
                            {
                                Content        = "登录",
                                AdminName      = p.Name,
                                AfterUpdate    = "",
                                BeforeUpdate   = "",
                                UpdateDateTime = DateTime.Now,
                            };
                            var logDal = new LogDal();
                            logDal.Add(logMode);
                            return(RedirectToAction("Index", "Frame"));
                        }
                        else
                        {
                            ModelState.AddModelError("", "密码不正确.");
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", "找不到该账号.");
                    }
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("", ex.Message);
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
コード例 #12
0
 public IHttpActionResult createAdmin([FromBody] AdministratorDal admin)
 {
     try
     {
         FlyingCenterSystem fly = FlyingCenterSystem.GetInstance();
         LoginToken <AdministratorLogin> token = new LoginToken <AdministratorLogin>();
         string _name = Request.GetRequestContext().Principal.Identity.Name;
         string _pass = Thread.CurrentPrincipal.Identity.Name;
         fly.GetAdministratorFacad(_name, _pass, out token).createOneAdmin(token, admin);
         return(Ok());
     }
     catch (Exception ex)
     {
         log.Error(ex);
         log.Info(ex.StackTrace);
         return(BadRequest(ex.Message));
     }
 }
コード例 #13
0
        public IHttpActionResult GetAirlineFromRedis([FromBody] AdministratorDal admin)
        {
            try
            {
                string[] result = new string[50];
                var      host   = "LocalHost";
                var      key    = "key";
                for (int i = 0; i < 50; i++)
                {
                    if (SetRedis.Get(host, key + i) != null)
                    {
                        result[i] = SetRedis.Get(host, key + i) + ",key :" + key + i;
                    }
                }

                return(Ok(result));
            }
            catch (Exception ex)
            {
                log.Error(ex);
                log.Info(ex.StackTrace);
                return(BadRequest(ex.Message));
            }
        }
コード例 #14
0
        // get admin by id
        public AdministratorDal Get(int id)
        {
            AdministratorDal admin      = new AdministratorDal();
            string           SqlCommand = "Get_Administrator_By_Id";

            using (SqlConnection con = new SqlConnection(ConnectionString))
            {
                SqlCommand cmd = new SqlCommand(SqlCommand, con);
                try
                {
                    cmd.Connection.Open();
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add(new SqlParameter(@"Administrator_Id", id));
                    SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.Default);
                    while (reader.Read() == true)
                    {
                        admin._Id        = (int)reader["Id"];
                        admin._User_Name = (string)reader["User_Name"];
                        admin._Password  = (string)reader["Password"];
                        admin.First_Name = (string)reader["First_Name"];
                        admin.Last_Name  = (string)reader["Last_Name"];
                        admin.Email      = (string)reader["Email"];
                    }
                    cmd.Connection.Close();
                    return(admin);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    cmd.Connection.Close();
                }
            }
        }
コード例 #15
0
        public bool Confirm(string name, long tz)
        {
            AdministratorDal dal = new AdministratorDal();

            return(dal.Confirm(name, tz));
        }