public ActionResult AddOrEdit([Bind(Include = "Id,UserName,PassWord,Right,CreateTime")] Model.Models.Users users) { users.CreateTime = DateTime.Now; bool issucessful = false; //Id值为0则是新增,其他为修改 if (users.Id == 0) { Model.Models.Users addusers = new Model.Models.Users() { UserName = users.UserName, PassWord = users.PassWord, Right = users.Right, CreateTime = users.CreateTime }; issucessful = _UsersService.AddEntity(addusers); } else { issucessful = _UsersService.EditEntity(users); } AjaxResult ajaxResult = null; if (issucessful) { ajaxResult = new AjaxResult() { Result = DoResult.Success, PromptMsg = "插入成功" }; } else { ajaxResult = new AjaxResult() { Result = DoResult.Failed, PromptMsg = "插入失败" }; } return(Json(ajaxResult)); }
public JsonResult AddUser(Entity.Users user, int?shopType) { //如果是测试账号则默认门店设置在45下面 if (user.IsIntention == true) { if (shopType == 1) { user.DefaultStoreID = 45; } else if (shopType == 2) { user.DefaultStoreID = 101; } else { return(Json(new Result(false, "该版本还未开通,无法添加"), JsonRequestBehavior.AllowGet)); } } IService.IUsersService usersService = ServiceFactory.Create <IUsersService>(); //是否需要账号 if (user.NeedAccount) { if (string.IsNullOrWhiteSpace(user.UserName) || string.IsNullOrWhiteSpace(user.Password)) { return(Json(new Result(false, "用户名和密码不能为空,若无需账号请选择‘不需要登录账号’"), JsonRequestBehavior.AllowGet)); } bool flage = usersService.Exists(t => t.UserName == user.UserName); if (flage) { return(Json(new Result(false, "已经存在同名用户,请更换"), JsonRequestBehavior.AllowGet)); } //添加账号PasswordSalt随机 user.PasswordSalt = Common.TextFilter.GetPasswordSalt();//Common.TextFilter.Substring(Guid.NewGuid().ToString("N"), 10, false); string endPassword = user.Password + user.PasswordSalt; //计算密码 user.Password = Common.SecureHelper.MD5(endPassword); } //user.DefaultStoreID = CurrentInfo.CurrentStore.ID; IStoresService storesService = ServiceFactory.Create <IStoresService>(); var storesModel = storesService.GetEntity(user.DefaultStoreID.ToString().ToInt32()); user.ShopsID = storesModel.ShopId; if (!string.IsNullOrWhiteSpace(user.Photo)) { //生成缩略图 并删除原图 string fileFullName = FileHelper.Move(user.Photo, "/Upload/Reality/" + CurrentInfo.CurrentStore.ID + "/UserImg/"); string extension = System.IO.Path.GetExtension(fileFullName); //缩略图路径 string thumbnailPath = ImgHelper.GetThumbnailPathByWidth(fileFullName, 60); //生成缩略图 ImgHelper.MakeThumbnail( System.Web.HttpContext.Current.Server.MapPath(fileFullName), System.Web.HttpContext.Current.Server.MapPath(thumbnailPath), 60, 60, "W", extension ); FileHelper.DeleteFile(System.Web.HttpContext.Current.Server.MapPath(fileFullName)); user.Photo = thumbnailPath; //user.Photo = FileHelper.Move(user.Photo, "/Upload/Reality/" + CurrentInfo.CurrentStore.ID + "/UserImg/"); } if (!string.IsNullOrWhiteSpace(user.IdcardPhoto)) { user.IdcardPhoto = FileHelper.Move(user.IdcardPhoto, "/Upload/Reality/" + CurrentInfo.CurrentStore.ID + "/UserImg/"); } user.CreateUserID = CurrentInfo.CurrentUser.ID; user.CreateTime = DateTime.Now; user.Disabled = false; bool success = false; using (TransactionScope transactionScope = TransactionScopeHelper.GetTran()) { var data = usersService.AddEntity(user); //if (data.WorkTypeID != null) //{ // AdddRelationUserWorkType(data.ID, Convert.ToInt32(data.WorkTypeID)); //} transactionScope.Complete(); success = data != null; } return(Json(new Result(success, ResultType.Add), JsonRequestBehavior.AllowGet)); }