Exemple #1
0
        public TempSysRole Delete(int Id)
        {
            // 通过token获取当前用户
            var userId = User.Identity.GetUserId();

            // 处理逻辑
            var oldModel = context.SysRoles.First(t => t.Id == Id);

            oldModel.IsDeleted            = true;
            oldModel.DeleteDate           = DateTime.Now;
            oldModel.DeleteUserId         = userId;
            context.Entry(oldModel).State = System.Data.Entity.EntityState.Modified;
            context.SaveChanges();

            // 处理返回值
            var tempSysRole = new TempSysRole
            {
                Id       = Id,
                RoleName = oldModel.RoleName,
                Menus    = oldModel.Menus
            };

            // 记录日志
            logger.Warn("删除角色:{0}", JsonConvert.SerializeObject(tempSysRole));

            return(tempSysRole);
        }
Exemple #2
0
        public IHttpActionResult Post(TempSysRole model)
        {
            // 通过token获取当前用户
            var userId = User.Identity.GetUserId();

            // 处理逻辑
            var newModel = new SysRole()
            {
                RoleName     = model.RoleName,
                Menus        = model.Menus,
                CreateDate   = DateTime.Now,
                CreateUserId = userId,
                IsDeleted    = false
            };

            context.SysRoles.Add(newModel);
            context.SaveChanges();

            // 处理返回值
            model.Id       = newModel.Id;
            model.RoleName = newModel.RoleName;
            model.Menus    = newModel.Menus;

            // 记录日志
            logger.Info("添加角色:{0}", JsonConvert.SerializeObject(model));

            return(Content <TempSysRole>(HttpStatusCode.Created, model));
        }
Exemple #3
0
        public TempSysRole Put(TempSysRole model)
        {
            // 通过token获取当前用户
            var userId = User.Identity.GetUserId();

            // 处理逻辑
            var oldModel = context.SysRoles.First(t => t.Id == model.Id);

            oldModel.RoleName     = model.RoleName;
            oldModel.Menus        = model.Menus;
            oldModel.UpdateDate   = DateTime.Now;
            oldModel.UpdateUserId = userId;

            context.Entry(oldModel).State = System.Data.Entity.EntityState.Modified;
            context.SaveChanges();

            // 处理返回值

            // 记录日志
            logger.Info("修改角色:{0}", JsonConvert.SerializeObject(model));

            return(model);
        }