Example #1
0
 public OpResult SaveRole(ProductRole obj)
 {
     if (obj.Id == 0)
     {
         obj.RoleId    = ProductRoleRepository.GetMaxInt(o => o.RoleId, whereLambda: o => o.RoleVerId == obj.RoleVerId);
         obj.CreateDT  = DateTime.Now;
         obj.CreateUID = CurrentUser.UID;
         ProductRoleRepository.Add(obj, false);
     }
     else
     {
         var role = ProductRoleRepository.Get(obj.Id);
         role.Title = obj.Title;
     }
     ProductRoleRepository.SaveChanges();
     return(OpResult.Success());
 }
Example #2
0
        public OpResult SaveRole(string roleVerId, string moduleId, int?productId, string title)
        {
            if (ProductRoleVerRepository.IsExists(o => o.ProductId == productId && o.Status == 0 && o.RoleVerId != roleVerId))
            {
                return(OpResult.Fail("已存在未发布的版本"));
            }
            var verId = roleVerId.IsNullOrEmpty() ? CommonService.GUID : roleVerId;

            if (ProductRoleRepository.IsExists(o => o.RoleVerId == verId && o.Title == title))
            {
                return(OpResult.Fail("该角色已存在!"));
            }
            var role = new ProductRole()
            {
                Title     = title,
                RoleVerId = verId,
                RoleId    = ProductRoleRepository.GetMaxInt(o => o.RoleId, whereLambda: o => o.RoleVerId == verId),
                CreateDT  = DateTime.Now,
                CreateUID = CurrentUser.UID
            };
            var ver = ProductRoleVerRepository.Find(o => o.RoleVerId == verId);

            if (ver == null)
            {
                ver = new ProductRoleVer()
                {
                    ModuleId  = moduleId,
                    ProductId = productId.GetValueOrDefault(),
                    RoleVerId = verId,
                };
                ver.UpdateDT  = ver.CreateDT = role.CreateDT;
                ver.UpdateUID = ver.CreateUID = role.CreateUID;
                ProductRoleVerRepository.Add(ver, false);
            }
            else
            {
                ver.ModuleId = moduleId;
            }
            ProductRoleRepository.Add(role, false);
            ProductRoleRepository.SaveChanges();
            return(OpResult.Success(data: new{ verId = verId, roleId = role.RoleId }));
        }