Пример #1
0
        public void CreateGroupFeature(string name, List <int> featureIds)
        {
            var newGroupFeatures = new List <GroupFeature>();
            var grp = GetGroup(name);

            if (null == grp)
            {
                return;
            }

            var groupFeatures = GroupFeature.Create(grp.GroupID, featureIds);

            foreach (var groupFeature in groupFeatures)
            {
                var exists = Context.GroupFeatures.Any(x =>
                                                       x.FeatureID == groupFeature.FeatureID &&
                                                       x.GroupID == groupFeature.GroupID &&
                                                       x.FunctionID == groupFeature.FunctionID);
                if (!exists)
                {
                    newGroupFeatures.Add(groupFeature);
                }
            }

            if (newGroupFeatures.Count > 0)
            {
                Context.AddRange(newGroupFeatures);
                Context.SaveChanges();
            }
        }
Пример #2
0
        public ActionResult DeleteConfirmed(Guid id)
        {
            GroupFeature groupFeature = db.GroupFeatures.Find(id);

            db.GroupFeatures.Remove(groupFeature);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Пример #3
0
 public ActionResult Edit([Bind(Include = "GroupFeatureID,UserGroupID,SystemFeatureID,CreateDateTime")] GroupFeature groupFeature)
 {
     if (ModelState.IsValid)
     {
         db.Entry(groupFeature).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(groupFeature));
 }
Пример #4
0
        public ActionResult Create([Bind(Include = "GroupFeatureID,UserGroupID,SystemFeatureID,CreateDateTime")] GroupFeature groupFeature)
        {
            if (ModelState.IsValid)
            {
                groupFeature.GroupFeatureID = Guid.NewGuid();
                db.GroupFeatures.Add(groupFeature);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(groupFeature));
        }
        public ActionResult ManageFeature(string[] SystemFeatureID)
        {
            bool bUpdate     = false;
            Guid UserGroupID = new Guid(CurrentUserGroupID);

            if (SystemFeatureID != null)
            {
                GroupFeature groupFeatureUpdate = new GroupFeature();
                groupFeatureUpdate.DeleteGroupFeatureByGroup(UserGroupID);

                foreach (string sSystemFeatureID in SystemFeatureID)
                {
                    Guid gSystemFeatureID = new Guid(sSystemFeatureID);
                    bUpdate = groupFeatureUpdate.InsertGroupFeature(UserGroupID, gSystemFeatureID);
                }
                if (bUpdate)
                {
                    return(RedirectToAction("UserGroup"));
                }
            }
            ViewBag.UserGroupID = UserGroupID;
            List <GroupFeaturesDisplay> groupFeatureDisplayList = new List <GroupFeaturesDisplay>();

            List <GroupFeature>  groupFeatureList  = db.GroupFeatures.Where(i => i.UserGroupID == UserGroupID).ToList <GroupFeature>();
            List <SystemFeature> systemFeatureList = db.SystemFeatures.ToList <SystemFeature>();

            foreach (SystemFeature systemFeature in systemFeatureList)
            {
                GroupFeaturesDisplay groupFeatureDisplay = new GroupFeaturesDisplay();
                groupFeatureDisplay.UserGroupID     = UserGroupID;
                groupFeatureDisplay.SystemFeatureID = systemFeature.SystemFeatureID;
                groupFeatureDisplay.FeatureName     = systemFeature.FeatureName;
                groupFeatureDisplay.ControllerName  = systemFeature.ControllerName;
                groupFeatureDisplay.ActionName      = systemFeature.ActionName;
                foreach (GroupFeature groupFeature in groupFeatureList)
                {
                    if (systemFeature.SystemFeatureID == groupFeature.SystemFeatureID)
                    {
                        groupFeatureDisplay.Selected = true;
                        break;
                    }
                    else
                    {
                        groupFeatureDisplay.Selected = false;
                    }
                }
                groupFeatureDisplayList.Add(groupFeatureDisplay);
            }
            return(View(groupFeatureDisplayList));
        }
Пример #6
0
        // GET: GroupFeatures/Edit/5
        public ActionResult Edit(Guid?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            GroupFeature groupFeature = db.GroupFeatures.Find(id);

            if (groupFeature == null)
            {
                return(HttpNotFound());
            }
            return(View(groupFeature));
        }
Пример #7
0
        public async Task <GroupDto> CreateGroup(CreateGroupDto dto)
        {
            await ValidateCreateGroup(dto);

            var now       = DateTime.UtcNow;
            var createdBy = _sessionService.UserId;

            using (IDbTransaction trans = this.DatabaseConnectService.Connection.BeginTransaction())
            {
                try
                {
                    var group = dto.ToGroup();
                    group.CreatedAt = now;
                    group.CreatedBy = createdBy;

                    await this.DatabaseConnectService.Connection.InsertAsync <Group>(group, x => x.AttachToTransaction(trans));

                    if (dto.Features.Length > 0)
                    {
                        foreach (var item in dto.Features)
                        {
                            var groupFeature = new GroupFeature
                            {
                                FeatureId  = item.Id,
                                GroupId    = group.Id,
                                CreatedAt  = now,
                                ModifiedAt = now
                            };

                            await this.DatabaseConnectService.Connection.InsertAsync <GroupFeature>(groupFeature, x => x.AttachToTransaction(trans));
                        }
                    }

                    trans.Commit();

                    _redisCache.Remove(CacheConst.AllGroup);

                    //return await GetGroupById(group.Id);

                    return(null);
                }
                catch (Exception e)
                {
                    trans.Rollback();
                    throw new BusinessException(e.Message, ErrorCode.INTERNAL_SERVER_ERROR);
                }
            }
        }