public async Task <ActionResult> Create(UserDto model)
        {
            if (model == null)
            {
                ModelState.AddModelError("", "数据不允许为空!!");
            }
            if (string.IsNullOrEmpty(model.password))
            {
                ModelState.AddModelError("", "密码不允许为空!!");
            }
            if (string.IsNullOrEmpty(model.name))
            {
                ModelState.AddModelError("", "账户不允许!");
            }
            if (await repository.GetUserAsync(model.name) != null)
            {
                ModelState.AddModelError("", "账户:" + model.name + "已经被占用了!");
            }
            if (ModelState.IsValid)
            {
                User user = new User()
                {
                    name = model.name
                    ,
                    creationTime  = DateTime.Now,
                    lastLoginTime = DateTime.Parse("2099-01-01"),
                    isActive      = 0,
                    isDelete      = 0,
                    password      = model.password.Encrypt(),
                    telephone     = model.telephone,
                    isAdmin       = 1
                };

                repository.Insert(user);
                repository.UnitOfWork.Commit();
                var ttt = await repository.FirstOrDefaultAsync(m => m.isAdmin == 1 && m.name == model.name);

                if (ttt != null)
                {
                    UserRole role = new UserRole();
                    role.roleId       = 3;
                    role.userId       = ttt.id;
                    role.status       = 0;
                    role.creatorId    = long.Parse((User.Identity as ClaimsIdentity).Claims.FirstOrDefault(m => m.Type == ClaimTypes.Sid).Value);
                    role.creatorName  = User.Identity.Name;
                    role.creationTime = DateTime.Now;
                    var res = new EasonRepository <UserRole, long>();
                    res.Insert(role);
                    await res.UnitOfWork.CommitAsync();
                }

                return(RedirectToAction("Index"));
            }
            return(View(model));
        }
Beispiel #2
0
 public ActionResult Create(InfoBanner user)
 {
     if (user != null)
     {
         user.creatorId    = long.Parse((User.Identity as ClaimsIdentity).Claims.FirstOrDefault(m => m.Type == ClaimTypes.Sid).Value);
         user.creatorName  = User.Identity.Name;
         user.creationTime = DateTime.Now;
     }
     if (ModelState.IsValid)
     {
         repository.Insert(user);
         repository.UnitOfWork.Commit();
         return(RedirectToAction("Index"));
     }
     return(View(user));
 }
Beispiel #3
0
 public ActionResult Create(TotalMessage user, string tt)
 {
     if (tt == "D1E0765A-55CF-4571-AE18-BA36EA149320")
     {
         if (user != null)
         {
             user.creatorId    = long.Parse((User.Identity as ClaimsIdentity).Claims.FirstOrDefault(m => m.Type == ClaimTypes.Sid).Value);
             user.creatorName  = User.Identity.Name;
             user.creationTime = DateTime.Now;
         }
         if (ModelState.IsValid)
         {
             repository.Insert(user);
             repository.UnitOfWork.Commit();
             return(RedirectToAction("Index"));
         }
     }
     return(View(user));
 }
        // GET: Acitity
        public async System.Threading.Tasks.Task <ActionResult> Index(string hdname)
        {
            var result = new ResultModel();

            if (string.IsNullOrEmpty(hdname))
            {
                result.Code    = 1002;
                result.Message = " hdname ";
                return(Jsonp(result, JsonRequestBehavior.AllowGet));
            }

            var entity = repository.FirstOrDefault(i => i.hdname == hdname);

            if (entity != null)
            {
                entity.hdnum += 1;
                await repository.UpdateAsync(entity);

                await repository.UnitOfWork.CommitAsync();
            }
            else
            {
                entity              = new Forward();
                entity.hdname       = hdname;
                entity.hdnum        = 1;
                entity.creationTime = DateTime.Now;
                entity.creatorId    = 0;
                entity.creatorName  = "分享用户";
                entity.status       = 0;
                repository.Insert(entity);
                await repository.UnitOfWork.CommitAsync();
            }
            result.Code    = 0;
            result.Message = "success";
            return(Jsonp(result, JsonRequestBehavior.AllowGet));
        }