Пример #1
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 }));
        }
Пример #2
0
 public OpResult SaveOrUpdate(ProductRoleVer obj)
 {
     if (obj.Id == 0)
     {
         obj.RoleVerId = CommonService.GUID;
         obj.CreateDT  = DateTime.Now;
         obj.UpdateDT  = obj.CreateDT;
         obj.UpdateUID = CurrentUser.UID;
         obj.CreateUID = obj.UpdateUID;
         ProductRoleVerRepository.Add(obj, false);
     }
     else
     {
         var product = ProductRoleVerRepository.Find(o => o.Id == obj.Id);
         product.UpdateUID = CurrentUser.UID;
         product.UpdateDT  = DateTime.Now;
     }
     ProductRoleVerRepository.SaveChanges();
     return(OpResult.Success());
 }