示例#1
0
        public string Post([Bind] Sys_GroupModel group)
        {
            var success = string.Empty;
            var model   = new Sys_GroupEntity
            {
                ID         = group.ID,
                Code       = group.Code,
                GroupName  = group.GroupName,
                IsActivate = group.IsActivate
            };
            var service = new Sys_GroupServices();

            if (group.ID != Guid.Empty)
            {
                group.ID = group.ID;
                success  = service.Edit <Sys_GroupEntity>(model) + ",1";
            }
            else
            {
                success  = service.Add <Sys_GroupEntity>(model) + ",0";
                group.ID = model.ID;
            }

            return(success);
        }
示例#2
0
        public Sys_GroupEntity GetSysGroupById(Guid id)
        {
            string          status         = string.Empty;
            var             result         = GetById <Sys_Group>(id, ref status);
            Sys_GroupEntity sysGroupEntity = null;

            if (result != null)
            {
                sysGroupEntity = result.CopyData <Sys_GroupEntity>();
            }
            return(sysGroupEntity);
        }
示例#3
0
        public Sys_GroupModel Put(Sys_GroupModel model)
        {
            var group = new Sys_GroupEntity
            {
                ID         = model.ID,
                Code       = model.Code,
                GroupName  = model.GroupName,
                IsActivate = model.IsActivate,
            };
            var service = new Sys_GroupServices();

            if (model.ID != Guid.Empty)
            {
                group.ID = model.ID;
                service.Edit <Sys_GroupEntity>(group);
            }
            else
            {
                service.Add <Sys_GroupEntity>(group);
            }

            return(model);
        }
        public Guid Post([FromBody] FormDataCollection grouppermissionInfo)
        {
            Guid groupId = Guid.Empty;

            if (grouppermissionInfo != null)
            {
                #region Lưu Sys_GroupEntity
                var  groupInfos = grouppermissionInfo.Where(p => !p.Key.Contains("allow")).Distinct().ToList();
                Guid id         = Guid.Empty;
                bool IsActivate = false;

                #region Get Group Info
                Guid.TryParse(groupInfos.Where(p => p.Key == "ID").Select(p => p.Value).FirstOrDefault(), out id);
                var code        = groupInfos.Where(p => p.Key == Sys_GroupModel.FieldNames.Code).Select(p => p.Value).FirstOrDefault();
                var description = groupInfos.Where(p => p.Key == Sys_GroupModel.FieldNames.Notes).Select(p => p.Value).FirstOrDefault();
                var groupName   = groupInfos.Where(p => p.Key == Sys_GroupModel.FieldNames.GroupName).Select(p => p.Value).FirstOrDefault();
                bool.TryParse(groupInfos.Where(p => p.Key == Sys_GroupModel.FieldNames.IsActivate).Select(p => p.Value).FirstOrDefault(), out IsActivate);
                #endregion

                var group = new Sys_GroupEntity()
                {
                    ID         = id,
                    IsActivate = IsActivate,
                    Code       = code,
                    Notes      = description,
                    GroupName  = groupName
                };
                var groupService = new Sys_GroupServices();
                if (group.ID == Guid.Empty)
                {
                    //add
                    var statusAdding = groupService.Add <Sys_GroupEntity>(group);
                    groupId = group.ID;
                }
                else
                {
                    //edit
                    string statusSysGroup = string.Empty;
                    groupId = id;
                    var statusEditing = groupService.GetSysGroupById(group.ID);
                    if (statusEditing != null)
                    {
                        statusEditing.IsActivate  = group.IsActivate;
                        statusEditing.Code        = group.Code;
                        statusEditing.Notes       = group.Notes;
                        statusEditing.Description = group.Notes;
                        statusEditing.GroupName   = group.GroupName;
                        groupService.Edit <Sys_GroupEntity>(statusEditing);
                    }
                }

                #endregion

                List <Guid>   listResourceId = new List <Guid>();
                List <string> lstValue       = grouppermissionInfo.Where(p => p.Key.Contains("allow") && p.Value != "0").Select(m => m.Value).Distinct().ToList();
                var           lstAdding      = new List <Sys_GroupPermission2Entity>();
                var           lstEditing     = new List <Sys_GroupPermission2Entity>();
                var           service        = new Sys_GroupPermissionServices();
                //[Tung.Ly 20150114] - Modify : lay danh sach Sys_GroupPermission2 bởi GroupID bằng entity thay vì dùng store
                // Dùng store không lấy được dữ liệu => nên tạm thời dùng entity
                var groupPermisstion2s = service.GetAllGroupPermissionByGroupId(groupId);
                foreach (string itemValue in lstValue)
                {
                    //lay thong tin nhom quyen
                    var  lstgrouppermissionInfo = grouppermissionInfo.Where(m => m.Key.Contains("allow") && m.Value == itemValue).ToList();
                    int  privilegeNumber        = 0;
                    Guid resourceId             = Guid.Empty;
                    Guid.TryParse(itemValue, out resourceId);
                    if (resourceId != Guid.Empty && !listResourceId.Any(p => p == resourceId))
                    {
                        listResourceId.Add(resourceId);
                    }

                    #region Get Privilege (View/Create/Modify/Delete/Export/Import)
                    foreach (var item in lstgrouppermissionInfo)
                    {
                        var lst    = item.Key.Split(new char[] { '_' });
                        int number = int.Parse(lst[2]);

                        switch (number)
                        {
                        case 1:
                            privilegeNumber = privilegeNumber + (int)PrivilegeType.View;
                            break;

                        case 2:
                            privilegeNumber = privilegeNumber + (int)PrivilegeType.Create;
                            break;

                        case 3:
                            privilegeNumber = privilegeNumber + (int)PrivilegeType.Modify;
                            break;

                        case 4:
                            privilegeNumber = privilegeNumber + (int)PrivilegeType.Delete;
                            break;

                        case 5:
                            privilegeNumber = privilegeNumber + (int)PrivilegeType.Export;
                            break;

                        case 6:
                            privilegeNumber = privilegeNumber + (int)PrivilegeType.Import;
                            break;
                        }
                    }
                    #endregion

                    #region Thêm/chỉnh sửa nhóm quyền

                    groupId = group.ID;
                    var groupPermisstion = groupPermisstion2s.Where(p => p.ResourceID == resourceId).FirstOrDefault();

                    if (groupPermisstion == null || groupPermisstion.ID == Guid.Empty)
                    {
                        groupPermisstion = new Sys_GroupPermission2Entity
                        {
                            GroupID         = groupId,
                            ResourceID      = resourceId,
                            PrivilegeNumber = privilegeNumber
                        };
                        if (lstAdding.FirstOrDefault(p => p.ResourceID == resourceId && p.GroupID == groupId) == null)
                        {
                            lstAdding.Add(groupPermisstion);
                        }
                    }
                    else
                    {
                        if (groupPermisstion.PrivilegeNumber != privilegeNumber)
                        {
                            groupPermisstion.PrivilegeNumber = privilegeNumber;
                            //check groupPermission exist
                            if (lstEditing.FirstOrDefault(p => p.ResourceID == resourceId && p.GroupID == groupId) == null)
                            {
                                lstEditing.Add(groupPermisstion);
                            }
                        }
                    }
                    #endregion
                }//close foreach

                #region Thêm/Chỉnh sửa danh sách nhóm quyền (GroupPermission)

                var gService = new Sys_GroupPermissionServices();
                gService.CreateOrUpdateGroupPermission(groupId, lstAdding, lstEditing, listResourceId);

                #endregion
            }
            return(groupId);
        }