Exemple #1
0
        public ActionResult Login(LoginModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new AjaxResult {
                    Status = "error", ErrorMsg = MVCHelper.GetValidMsg(ModelState)
                }));
            }
            //ToDo:有漏洞跟验证码有关
            string verifyCode = model.VerifyCode;

            //验证码错误
            if (verifyCode != (string)TempData["verifyCode"])
            {
                return(Json(new AjaxResult {
                    Status = "error", ErrorMsg = "验证码错误"
                }));
            }
            bool result = userService.CheckLogin(model.PhoneNum, model.Password);

            if (result)
            {
                //把当前登录用户的Id存到Session,给后面检查“当前Session登录的这个用户有没有***的权限”
                Session["LoginUserId"] = userService.GetByPhoneNum(model.PhoneNum).Id;
                return(Json(new AjaxResult {
                    Status = "ok"
                }));
            }
            else
            {
                return(Json(new AjaxResult {
                    Status = "error", ErrorMsg = "用户名或密码错误"
                }));
            }
        }
Exemple #2
0
        // GET: Default
        public ActionResult Index()
        {
            string html = MVCHelper.RenderViewToString(ControllerContext, "~/Views/Default/Index.cshtml", "hello");

            System.IO.File.WriteAllText("d:/1.txt", html);
            return(View());
        }
Exemple #3
0
        public ActionResult Login(UserLoginModel model)
        {
            //提交表单合法性验证
            if (!ModelState.IsValid)
            {
                return(Json(new AjaxResult
                {
                    Status = "error",
                    ErrorMsg = MVCHelper.GetValidMsg(ModelState)
                }));
            }
            var user = userService.GetByPhoneNum(model.PhoneNum);

            if (user != null)
            {
                //判断
                if (userService.IsLocked(user.Id))
                {
                    //TimeSpan代表时间段,日期相减就代表相差的时间段(30分钟-(当前时间-最后一次登录错误时间))
                    TimeSpan?leftTimeSpan =
                        TimeSpan.FromMinutes(30) - (DateTime.Now - user.LastLoginErrorDateTime);
                    return(Json(new AjaxResult
                    {
                        Status = "error",
                        ErrorMsg = "账号已被锁定,请"
                                   + (int)leftTimeSpan.Value.TotalMinutes + "分钟后再试"
                    }));
                }
            }

            bool isOK = userService.CheckLogin(model.PhoneNum, model.Password);

            if (isOK)
            {
                //一旦登录成功,就重置所有登录错误信息,避免影响下一次登录
                userService.ResetLoginError(user.Id);

                //把当前登录用户信息存入Session
                Session["UserId"] = user.Id;
                Session["CityId"] = user.CityId;

                return(Json(new AjaxResult
                {
                    Status = "ok"
                }));
            }
            else
            {
                if (user != null)//存在这个手机号
                {
                    //登入失败增加登录错误次数
                    userService.IncrLoginError(user.Id);
                }
                return(Json(new AjaxResult
                {
                    Status = "error",
                    ErrorMsg = "用户名或者密码错误"
                }));
            }
        }
Exemple #4
0
        public ActionResult Login(LoginModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new AjaxResult {
                    Status = "error", ErrorMsg = MVCHelper.GetValidMsg(ModelState)
                }));
            }

            //if (model.VerifyCode != (string)TempData["verifyCode"])
            //{
            //    return Json(new AjaxResult { Status = "error", ErrorMsg = "验证码错误" });
            //}

            bool result = UserService.CheckLogin(model.UserName, model.Password);

            if (result)
            {
                //Session中保存当前登录用户Id
                //Session["LoginUserId"]
                //    = UserService.GetByUserName(model.UserName).Id;
                Session["LoginUserId"]
                    = UserService.GetByPhoneNum(model.UserName).Id;
                //给后面检查“当前Session登录的这个用户有没有***的权限”
                return(Json(new AjaxResult {
                    Status = "ok"
                }));
            }
            else
            {
                return(Json(new AjaxResult {
                    Status = "error", ErrorMsg = "用户名或者密码错误"
                }));
            }
        }
Exemple #5
0
        public ActionResult Login(string user, string pwd)
        {
            string cntroller = string.Empty, action = string.Empty;

            try
            {
                Tbl_LoginMaster obj = new Tbl_LoginMaster();
                if (MVCHelper.CheckLogin(user.Trim(), pwd.Trim(), ref obj))
                {
                    if (Convert.ToBoolean(obj.IsClient))
                    {
                        action = "Userpage"; cntroller = "IP";
                    }
                    else
                    {
                        action = "Home"; cntroller = "IP";
                    }
                }
                else
                {
                    action = "Login"; cntroller = "Login";
                    TempData["invalidmsg"] = "Wrong Credential!!!.";
                }
                return(RedirectToAction(action, cntroller));
            }
            catch (Exception ex)
            {
                TempData["invalidmsg"] = "Somthing wrong!!!.";
                return(View());
            }
        }
Exemple #6
0
        /// <summary>
        /// 返回店铺下拉列表
        /// </summary>
        public SelectList GetStoreList(string seled)
        {
            B_Content conBll = new B_Content();
            DataTable dt     = conBll.Store_Sel();

            return(MVCHelper.ToSelectList(dt, "Title", "GeneralID", seled));
        }
Exemple #7
0
        public ActionResult Login(AdminUserLoginModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new AjaxResult {
                    Status = "error", ErrorMsg = MVCHelper.GetValidMsg(ModelState)
                }));
            }

            //settingService.UpdateValue("前端奖品图片地址", "http://104.151.50.99:8225");

            if (adminService.CheckLogin(model.Name, model.Password))
            {
                Session["AdminUserId"] = adminService.GetByName(model.Name).Id;
                return(Json(new AjaxResult {
                    Status = "redirect", Data = "/home/index"
                }));
            }
            else
            {
                return(Json(new AjaxResult {
                    Status = "error", ErrorMsg = "用户名密码错误"
                }));
            }
        }
Exemple #8
0
        public ActionResult Add(UserAddDTO dto)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new AjaxResult
                {
                    Status = "error",
                    ErrorMsg = MVCHelper.GetValidMsg(ModelState)
                }));
            }

            var data = userService.AddUser(dto);

            if (data > 0)
            {
                return(Json(new AjaxResult {
                    Status = "ok"
                }));
            }
            else
            {
                return(Json(new AjaxResult {
                    Status = "error", ErrorMsg = "添加失败!"
                }));
            }
        }
Exemple #9
0
 public ActionResult Login(LoginModel model)
 {
     if (!ModelState.IsValid)
     {
         return(Json(new AjaxResult
         {
             Status = "error",
             ErrorMsg = MVCHelper.GetValidMsg(ModelState)
         }));
     }
     if (model.Code != (string)TempData["verifyCode"])
     {
         return(Json(new AjaxResult {
             Status = "error", ErrorMsg = "验证码错误!"
         }));
     }
     if (adminUserService.CheckLogin(model.Name, model.PassWord))
     {
         Session["LoginAdminId"] = adminUserService.GetByName(model.Name).Id;
         return(Json(new AjaxResult {
             Status = "ok"
         }));
     }
     else
     {
         return(Json(new AjaxResult {
             Status = "error", ErrorMsg = "账号密码错误!"
         }));
     }
 }
Exemple #10
0
        public ActionResult Add(AdminUserAddNewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new AjaxResult()
                {
                    Status = "error", ErrorMsg = MVCHelper.GetValidMesg(ModelState)
                }));
            }

            var user = AdminUserService.GetByPhoneNum(model.PhoneNum);

            if (user != null)
            {
                return(Json(new AjaxResult()
                {
                    Status = "error", ErrorMsg = "该手机号已被注册"
                }));
            }
            //发现在service里面也判断了一次手机是否注册,感觉越早判断越好,service那个就没必要了
            //TODO:这里应该用事务
            long adminUserId = AdminUserService.AddAdminUser(model.Name, model.PhoneNum, model.PassWord, model.Email, model.CityId);

            RoleService.AddRoleIds(adminUserId, model.RoleIds);

            return(Json(new AjaxResult()
            {
                Status = "ok"
            }));
        }
Exemple #11
0
        public void Can_Edit_Sound()
        {
            // Arrange - create the mock repository
            var mock = new Mock <IRepository <TimerSound> >();

            mock.Setup(m => m.GetAll()).Returns(new[]
            {
                new TimerSound {
                    Name = "Apple", Data = new byte[] { 0x01 }, ID = 1
                },
                new TimerSound {
                    Name = "Orange", Data = new byte[] { 0x02 }, ID = 2
                },
                new TimerSound {
                    Name = "Banana", Data = new byte[] { 0x03 }, ID = 3
                }
            }.AsQueryable());

            // Arrange - create a controller
            var target = new TimerController(null, mock.Object, null);

            // Act
            var p1 = MVCHelper.GetViewModel <EditSoundViewModel>(target.EditSound(1));
            var p2 = MVCHelper.GetViewModel <EditSoundViewModel>(target.EditSound(2));
            var p3 = MVCHelper.GetViewModel <EditSoundViewModel>(target.EditSound(3));

            // Assert
            Assert.Equal(1, p1.ID);
            Assert.Equal(2, p2.ID);
            Assert.Equal(3, p3.ID);
        }
Exemple #12
0
        public ActionResult Login(LoginModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new AjaxResult {
                    Status = "error", ErrorMsg = MVCHelper.GetValidMsg(ModelState)
                }));
            }
            if (TempData["VarifyCode"] == null || model.VarifyCode != (string)TempData["VarifyCode"])
            {
                return(Json(new AjaxResult {
                    Status = "error", ErrorMsg = "验证码错误"
                }));
            }
            bool result = AdminUserService.CheckLogin(model.PhoneNum, model.Password);

            if (result)
            {
                Session["LoginUserId"] = AdminUserService.GetByPhoneNum(model.PhoneNum).Id;
                return(Json(new AjaxResult {
                    Status = "ok", Data = "/Main/Index"
                }));
            }
            else
            {
                return(Json(new AjaxResult {
                    Status = "error", ErrorMsg = "用户名或密码错误"
                }));
            }
        }
 public ActionResult Edit(int id)
 {
     ViewBag.ID = id;
     MVCHelper.DDLDepartment(this);
     MVCHelper.DDLCountry(this);
     return(View());
 }
 public ActionResult Add()
 {
     MVCHelper.DDLDepartment(this);
     MVCHelper.DDLCountry(this);
     //MVCHelper.DDLState(this);
     return(View());
 }
        public ActionResult Edit(EmployeeVM objVM)
        {
            try
            {
                using (var objBLL = new EmployeeBLL())
                {
                    objVM.Logo = Helper.FilePaths(Server.MapPath("~/content/employee/" + objVM.ID + "/img/"));
                    //objVM.LastActivityBy = ActiveUser.ID;
                    int id = objBLL.SaveData(objVM);
                    if (id > 0)
                    {
                        TempData[Toastr.SUCCESS] = "Record updated successfully!";
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        TempData[Toastr.ERROR] = "Failed to update record!";
                    }
                }
            }
            catch (Exception ex)
            {
                TempData[Toastr.ERROR] = "Something went wrong!";
                Helper.LogException(ex);
            }

            MVCHelper.DDLDepartment(this, selected: objVM.DepartmentId);
            MVCHelper.DDLCountry(this, selected: objVM.Country);
            MVCHelper.DDLState(this, selected: objVM.State, countryName: objVM.Country);
            return(View(objVM));
        }
Exemple #16
0
        //贴子搜索
        public IActionResult PostSearch()
        {
            int       uid     = DataConvert.CLng(RequestEx["uid"]);
            string    skey    = DataConvert.CStr(RequestEx["skey"]).Trim();
            bool      sellike = DataConvert.CLng(RequestEx["islike"]) > 0 ? true : false;
            string    skeyTlp = "\"<span style='color:#ff6a00;'>{0}</span>\"";
            VM_PClass model   = new VM_PClass();

            model.cateMod          = new M_GuestBookCate();
            model.cateMod.BarImage = "/UploadFiles/timg.jpg";
            model.setting          = barBll.SelPage(CPage, PSize, 0, uid, skey, true);
            model.setting.url      = MVCHelper.GetAction("PostSearch", Request);
            if (Request.IsAjax())
            {
                return(PartialView("PClass_PostList", model));
            }
            if (!string.IsNullOrEmpty(skey))
            {
                model.cateMod.Desc     = "相关" + string.Format(skeyTlp, skey.Replace("|", "、")) + "的贴子";
                model.cateMod.CateName = skey + "\"的贴子";
            }
            if (uid > 0)
            {
                M_UserInfo smu = buser.GetUserByUserID(uid);
                model.cateMod.BarImage = smu.UserFace;
                model.cateMod.CateName = smu.HoneyName + "的贴子";
                model.cateMod.Desc     = string.Format(skeyTlp, smu.HoneyName) + "的贴子";
            }
            if (sellike)
            {
                model.cateMod.CateName = "我的收藏";
                model.cateMod.Desc     = string.Format(skeyTlp, "我的收藏");
            }
            return(View(model));
        }
Exemple #17
0
        public ActionResult PageTemplateAdd()
        {
            M_PageReg  regMod  = new M_PageReg();
            M_Templata tempMod = new M_Templata();

            regMod = regBll.SelReturnModel(RegID);
            if (Mid > 0)
            {
                tempMod = tempBll.SelReturnModel(Mid);
                regMod  = regBll.SelModelByUid(tempMod.UserID);
                RegID   = regMod.ID;
            }
            //用户所属RegID,公有为-1
            if (regMod == null)
            {
                function.WriteErrMsg("RegID参数错误"); return(null);
            }
            DataTable templist = tempBll.Sel(regMod.UserID);
            DataTable styleDT  = styleBll.Sel();
            B_Page    pageBll  = new B_Page(tempMod.Modelinfo);

            pageBll.moddt     = modBll.SelByType("4");
            ViewBag.pageBll   = pageBll;
            ViewBag.styleList = MVCHelper.ToSelectList(styleDT, "PageNodeName", "PageNodeName", tempMod.UserGroup);
            ViewBag.templist  = templist;
            return(View(tempMod));
        }
        public ActionResult Add(AdminUserAddModel model)
        {
            if (!ModelState.IsValid)
            {
                string msg = MVCHelper.GetValidMsg(ModelState);
                return(Json(new AjaxResult {
                    Status = "error", ErrorMsg = msg
                }));
            }
            //服务器端的校验必不可少
            bool exists = userService.GetByPhoneNum(model.PhoneNum) != null;

            if (exists)
            {
                return(Json(new AjaxResult
                {
                    Status = "error",
                    ErrorMsg = "手机号已经存在"
                }));
            }
            long?cityId = null;

            if (model.CityId != 0)//cityId=0的时候为“总部”
            {
                cityId = model.CityId;
            }
            long userId = userService.AddAdminUser(model.Name,
                                                   model.PhoneNum, model.Password, model.Email, cityId);

            roleService.AddRoleIds(userId, model.RoleIds);
            return(Json(new AjaxResult {
                Status = "ok"
            }));
        }
Exemple #19
0
        public ActionResult Index()
        {
            M_CommonData storeMod = conBll.SelMyStore(mu.UserName);

            if (storeMod == null)
            {
                return(RedirectToAction("StoreApply")); //申请店铺
            }
            else if (storeMod.Status != 99)             //等待审核
            {
                return(RedirectToAction("StoreEdit"));
            }
            else
            {
                DataTable cmdinfo = conBll.GetContent(storeMod.GeneralID);
                if (cmdinfo.Rows.Count < 1)
                {
                    function.WriteErrMsg("店铺信息不完整"); return(Content(""));
                }
                DataRow           dr    = cmdinfo.Rows[0];
                DataTable         sstDT = sstbll.GetStyleByModel(Convert.ToInt32(dr["StoreModelID"]), 1);
                M_StoreStyleTable sst   = sstbll.GetStyleByID(Convert.ToInt32(dr["StoreStyleID"]));
                ViewBag.sstdp     = MVCHelper.ToSelectList(sstDT, "StyleName", "ID", dr["StoreStyleID"].ToString());
                ViewBag.dr        = dr;
                ViewBag.sstimg    = sst == null ? "" : function.GetImgUrl(sst.StylePic);
                ViewBag.modelhtml = fieldBll.InputallHtml(DataConvert.CLng(dr["StoreModelID"]), 0, new ModelConfig()
                {
                    ValueDT = cmdinfo
                });
            }
            return(View(storeMod));
        }
Exemple #20
0
        public ActionResult DefaultIssueEdit(Guid defaultIssueId)
        {
            var contract = new CrudeDefaultIssueServiceClient().FetchByDefaultIssueId(defaultIssueId);

            ViewBag.DefaultIssueTypeRcd =
                new SelectList(new CrudeDefaultIssueTypeRefServiceClient().FetchAll(),
                               "DefaultIssueTypeRcd",
                               "DefaultIssueTypeName",
                               contract.DefaultIssueTypeRcd
                               );

            ViewBag.DefaultIssueStatusRcd =
                new SelectList(new CrudeDefaultIssueStatusRefServiceClient().FetchAll(),
                               "DefaultIssueStatusRcd",
                               "DefaultIssueStatusName",
                               contract.DefaultIssueStatusRcd
                               );

            if (contract.DefaultErrorId != Guid.Empty)
            {
                ViewBag.DefaultErrorId =
                    new SelectList(new CrudeDefaultErrorServiceClient().FetchAll(),
                                   "DefaultErrorId",
                                   "MethodName",
                                   contract.DefaultErrorId
                                   );
            }

            MVCHelper.Resolve(Request, "Default", "DefaultIssue", "DefaultIssueEdit");

            return(View(
                       "~/Views/Default/DefaultIssue/DefaultIssueEdit.cshtml",
                       contract
                       ));
        }
 public ActionResult Login(AdminLogin adminLogin)
 {
     if (ModelState.IsValid)
     {
         if (adminLogin.Code == TempData["code"].ToString())
         {
             bool i = Logins.Login(adminLogin.PhoneNum, adminLogin.Pwd);
             if (i)
             {
                 Session["LoginId"] = adminUserService.GetPhoneUpdate(adminLogin.PhoneNum);
                 return(Json(new AjaxReault {
                     Statin = "ok"
                 }));
             }
             else
             {
                 return(Json(new AjaxReault {
                     Msg = "用户名或密码不正确"
                 }));
             }
         }
         else
         {
             return(Json(new AjaxReault {
                 Msg = "验证码不一致!"
             }));
         }
     }
     else
     {
         return(Json(new AjaxReault {
             Statin = "no", Msg = MVCHelper.GetValidMsg(ModelState)
         }));
     }
 }
Exemple #22
0
        public static void Main(string[] args)
        {
            /*
             * AssertEqual(Add(1,1),2);//TestCase
             * AssertEqual(Add(1, 0),1);//TestCase
             * AssertEqual(Add(0, 0),0);
             * AssertEqual(Add(-1,1),0);*/
            /*
             * using (ZSZDbContext ctx = new ZSZDbContext())
             * {
             *  ctx.Database.Delete();
             *  ctx.Database.Create();
             * }*/

            NameValueCollection nvc = new NameValueCollection();

            nvc["id"]   = "5";
            nvc["age"]  = "6";
            nvc["name"] = "如鹏网";
            Console.WriteLine(MVCHelper.ToQueryString(nvc));
            Console.WriteLine(MVCHelper.RemoveQueryString(nvc, "age"));
            Console.WriteLine(MVCHelper.RemoveQueryString(nvc, "aaaa"));
            Console.WriteLine(MVCHelper.UpdateQueryString(nvc, "age", "888"));
            Console.WriteLine(MVCHelper.UpdateQueryString(nvc, "height", "1.80"));
            Console.WriteLine("ok");
            Console.ReadKey();
        }
Exemple #23
0
 public ActionResult Login(LoginModel model)
 {
     if (!ModelState.IsValid)
     {
         return(Json(new AjaxResult {
             Status = "error", ErrorMsg = MVCHelper.GetValidMsg(ModelState)
         }));
     }
     if (model.VerifyCode != (string)TempData["verifyCode"])
     {
         return(Json(new AjaxResult {
             Status = "error", ErrorMsg = "验证码错误"
         }));
     }
     if (userService.CheckLogin(model.PhoneNum, model.Password))
     {
         Session["AdminUserId"] = userService.GetByPhoneNum(model.PhoneNum).Id;
         return(Json(new AjaxResult {
             Status = "ok"
         }));
     }
     else
     {
         return(Json(new AjaxResult {
             Status = "error", ErrorMsg = "手机号密码错误"
         }));
     }
 }
Exemple #24
0
        public void Cannot_Edit_Nonexistent_Activity()
        {
            // Arrange - create the mock repository
            var mock = new Mock <IRepository <TimerActivity> >();

            mock.Setup(m => m.GetAll()).Returns(new[]
            {
                new TimerActivity {
                    Name = "Apple", ID = 1
                },
                new TimerActivity {
                    Name = "Orange", ID = 2
                },
                new TimerActivity {
                    Name = "Banana", ID = 3
                }
            }.AsQueryable());

            // Arrange - create a controller
            var target = new TimerController(mock.Object, null, null);


            // Act
            var result = MVCHelper.GetViewModel <TimerActivity>(target.EditActivity(4));

            // Assert
            Assert.Null(result);
        }
Exemple #25
0
        public JsonResult Login(AdminLoginModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new AjaxResult {
                    Status = "error", ErrorMsg = MVCHelper.GetValidMsg(ModelState)
                }));
            }
            if ((string)TempData["VerifyCode"] != model.VerifyCode)
            {
                return(Json(new AjaxResult {
                    Status = "error", ErrorMsg = "验证码错误"
                }));
            }
            bool result = AdminUserService.CheckLogin(model.PhoneNum, model.Password);

            if (result)
            {
                Session["LoginUserId"] = AdminUserService.GetByPhoneNum(model.PhoneNum).Id;
                return(Json(new AjaxResult {
                    Status = "ok"
                }));
            }
            else
            {
                return(Json(new AjaxResult {
                    Status = "error", ErrorMsg = "用户名或者密码错误"
                }));
            }
        }
Exemple #26
0
        public void Can_Edit_Activity()
        {
            // Arrange - create the mock repository
            var mock = new Mock <IRepository <TimerActivity> >();

            mock.Setup(m => m.GetAll()).Returns(new[]
            {
                new TimerActivity {
                    Name = "Apple", ID = 1
                },
                new TimerActivity {
                    Name = "Orange", ID = 2
                },
                new TimerActivity {
                    Name = "Banana", ID = 3
                }
            }.AsQueryable());

            // Arrange - create a controller
            var target = new TimerController(mock.Object, null, null);

            // Act
            var p1 = MVCHelper.GetViewModel <CaptionActivity>(target.EditActivity(1));
            var p2 = MVCHelper.GetViewModel <CaptionActivity>(target.EditActivity(2));
            var p3 = MVCHelper.GetViewModel <CaptionActivity>(target.EditActivity(3));

            // Assert
            Assert.Equal(1, p1.Activity.ID);
            Assert.Equal(2, p2.Activity.ID);
            Assert.Equal(3, p3.Activity.ID);
        }
Exemple #27
0
        public void EditActivities_Contains_All_Activities()
        {
            // Arrange - create the mock repository
            var mock = new Mock <IRepository <TimerActivity> >();

            mock.Setup(m => m.GetAll()).Returns(new[]
            {
                new TimerActivity {
                    Name = "Apple"
                },
                new TimerActivity {
                    Name = "Orange"
                },
                new TimerActivity {
                    Name = "Banana"
                }
            }.AsQueryable());

            // Arrange - create a controller
            var target = new TimerController(mock.Object, null, null);

            // Action
            var result
                = MVCHelper.GetViewModel <IEnumerable <TimerActivity> >(target.EditActivities())?.ToArray();

            // Assert
            Assert.NotNull(result);
            Assert.Equal(3, result.Length);
            Assert.Equal("Apple", result[0].Name);
            Assert.Equal("Orange", result[1].Name);
            Assert.Equal("Banana", result[2].Name);
        }
        public ActionResult Login(string username, string password, string Verify)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new AjaxResult
                {
                    Status = "error",
                    ErrorMsg = MVCHelper.GetValidMsg(ModelState)
                }));
            }
            var yzm = (string)TempData["verifyCodeHome"];

            if (Verify != yzm)
            {
                return(Json(new AjaxResult {
                    Status = "error", ErrorMsg = "验证码错误!"
                }));
            }

            if (userService.CheckLogin(username, password))
            {
                var user = userService.GetAll().FirstOrDefault(e => e.UserName == username);
                CommonHelper.WriteCookie("UserLogin", DESEncrypt.Encrypt(JsonConvert.SerializeObject(user)), 7200);
                return(Json(new AjaxResult {
                    Status = "ok"
                }));
            }
            else
            {
                return(Json(new AjaxResult {
                    Status = "error", ErrorMsg = "账号密码错误!"
                }));
            }
        }
        public void History_Contains_All_Logs()
        {
            // Arrange - create the mock repository
            var mock = new Mock <IRepository <TimerLog> >();

            mock.Setup(m => m.GetAll()).Returns(new[]
            {
                new TimerLog {
                    Activity = new TimerActivity(), Date = DateTime.Now, ID = 1
                },
                new TimerLog {
                    Activity = new TimerActivity(), Date = DateTime.Now, ID = 2
                },
                new TimerLog {
                    Activity = new TimerActivity(), Date = DateTime.Now, ID = 3
                }
            }.AsQueryable);

            // Arrange - create a controller
            var target = new TimerController(null, null, mock.Object);

            // Action
            var result
                = MVCHelper.GetViewModel <IEnumerable <TimerLog> >(target.History())?.ToArray();

            // Assert
            Assert.NotNull(result);
            Assert.Equal(3, result.Length);
            Assert.Equal(1, result[0].ID);
            Assert.Equal(2, result[1].ID);
            Assert.Equal(3, result[2].ID);
        }
Exemple #30
0
 public ActionResult Add()
 {
     ViewBag.TempPath = DateTime.Now.Ticks;
     MVCHelper.DDLCountry(this);
     MVCHelper.DDLState(this);
     MVCHelper.DDLDepartment(this);
     return(PartialView());
 }