예제 #1
0
        // GET api/<controller>/5
        public Sys_GroupModel Getbyid(Guid id)
        {
            var service = new Sys_GroupServices();
            var result = service.GetSysGroupById(id);
            var sysGroupModel = new Sys_GroupModel
            {
                ID = result.ID,
                Code = result.Code,
                GroupName = result.GroupName,
                IsActivate = result.IsActivate,
                Notes = result.Notes
            };
            return sysGroupModel;

        }
예제 #2
0
        // GET api/<controller>
        /// <summary>
        /// Lấy tất cả dữ liệu
        /// </summary>
        /// <returns></returns>
        public IQueryable<Sys_GroupModel> Get()
        {
            string status = string.Empty;
            var service = new Sys_GroupServices();
            var list = service.GetAllUseEntity<Sys_GroupEntity>(ref status).AsQueryable<Sys_GroupEntity>();

            return list.Select(item => new Sys_GroupModel
            {
                ID = item.ID,
                GroupName = item.GroupName,
                Code = item.Code,
                IsActivate = item.IsActivate,
                Notes = item.Description
            });
        }
예제 #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;
        }
예제 #4
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;
        }
예제 #5
0
 // DELETE api/<controller>/5
 public void Delete(Guid id)
 {
     var service = new Sys_GroupServices();
     var result = service.Delete<Sys_GroupEntity>(id);//delete nhóm (sys_Group)
     
     if (id != Guid.Empty)
     {
         //delete ds nhóm quyền (sys_GroupPermission2)
         string status = string.Empty;
         BaseService baseService = new BaseService();
         List<object> lstObj = new List<object>();
         lstObj.Add(id);
         service.UpdateData<Sys_GroupPermission2Entity>(lstObj, ConstantSql.hrm_sys_sp_delete_GroupPermission2, ref status);
     }
 }
예제 #6
0
        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;
        }