public ActionResult Edit(AccountModel model)
        {
            var entity = _account.GetById(model.Id);

            if (entity == null)
            {
                int exsitCount = _account.Quyer()
                                 .Where(s => s.LoginName == model.LoginName.Trim() || s.Name == model.Name.Trim())
                                 .Count();
                if (exsitCount > 0)
                {
                    ModelState.AddModelError("", "登录名或用户已存在");
                    return(View(model));
                }

                entity          = new Account();
                entity.Password = "******";
                _account.Inserter(entity);
            }

            entity.Age       = model.Age;
            entity.Name      = model.Name;
            entity.Remark    = model.Remark;
            entity.LoginName = model.LoginName;

            _account.Save();

            var list = _account.Quyer().ToList().Select(s => {
                var m    = new AccountModel();
                m.Id     = s.Id;
                m.Age    = s.Age;
                m.Name   = s.Name;
                m.Remark = s.Remark;
                return(m);
            }).ToList();

            var cacheEntryOptions = new MemoryCacheEntryOptions()
                                    // Keep in cache for this time, reset time if accessed.
                                    .SetSlidingExpiration(TimeSpan.FromDays(3));

            _cache.Remove("userlist");
            _cache.Set("userlist", list, cacheEntryOptions);

            return(RedirectToAction("list"));
        }
Example #2
0
        public ActionResult List()
        {
            var list = _fileMgmt.Quyer().ToList();

            return(View(list));
        }