Exemple #1
0
        public override DTO.EditFormData GetData(int id, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            DTO.EditFormData data = new DTO.EditFormData();
            data.Data                   = new DTO.UserProfile();
            data.Data.Permissions       = new List <DTO.Permission>();
            data.Data.FactoryAccesses   = new List <DTO.FactoryAccess>();
            data.Data.EmployeeFactories = new List <DTO.EmployeeFactory>();

            data.InternalCompanies   = new List <Support.DTO.InternalCompany>();
            data.InternalDepartments = new List <Support.DTO.InternalDepartment>();
            data.Locations           = new List <Support.DTO.Location>();
            data.UserGroups          = new List <Support.DTO.UserGroup>();
            data.Managers            = new List <Support.DTO.Employee>();
            data.JobLevels           = new List <Support.DTO.JobLevel>();
            data.Factories           = new List <Support.DTO.Factory>();

            //try to get data
            try
            {
                using (User2MngEntities context = CreateContext())
                {
                    data.Data = converter.DB2DTO_UserProfile(context.User2Mng_UserProfile_View.FirstOrDefault(o => o.UserId == id));

                    data.Data.Permissions = converter.DB2DTO_UserGroupPermissionList(context.User2Mng_UserGroupPermission_View.Where(o => o.UserGroupID == data.Data.UserGroupID).ToList());
                    List <DTO.Permission> permissions = converter.DB2DTO_UserPermissionList(context.User2Mng_UserPermission_View.Where(o => o.UserID == id).ToList());
                    DTO.Permission        dtoTmpPermission;
                    foreach (DTO.Permission dtoPermission in permissions)
                    {
                        dtoTmpPermission = data.Data.Permissions.FirstOrDefault(o => o.ModuleID == dtoPermission.ModuleID);

                        if (dtoTmpPermission != null)
                        {
                            dtoTmpPermission.UserPermissionID = dtoPermission.UserPermissionID;

                            if (!dtoTmpPermission.CanCreate)
                            {
                                dtoTmpPermission.CanCreateEditable = true;
                            }
                            if (dtoPermission.CanCreate)
                            {
                                dtoTmpPermission.CanCreate = true;
                            }

                            if (!dtoTmpPermission.CanRead)
                            {
                                dtoTmpPermission.CanReadEditable = true;
                            }
                            if (dtoPermission.CanRead)
                            {
                                dtoTmpPermission.CanRead = true;
                            }

                            if (!dtoTmpPermission.CanUpdate)
                            {
                                dtoTmpPermission.CanUpdateEditable = true;
                            }
                            if (dtoPermission.CanUpdate)
                            {
                                dtoTmpPermission.CanUpdate = true;
                            }

                            if (!dtoTmpPermission.CanDelete)
                            {
                                dtoTmpPermission.CanDeleteEditable = true;
                            }
                            if (dtoPermission.CanDelete)
                            {
                                dtoTmpPermission.CanDelete = true;
                            }

                            if (!dtoTmpPermission.CanPrint)
                            {
                                dtoTmpPermission.CanPrintEditable = true;
                            }
                            if (dtoPermission.CanPrint)
                            {
                                dtoTmpPermission.CanPrint = true;
                            }

                            if (!dtoTmpPermission.CanApprove)
                            {
                                dtoTmpPermission.CanApproveEditable = true;
                            }
                            if (dtoPermission.CanApprove)
                            {
                                dtoTmpPermission.CanApprove = true;
                            }

                            if (!dtoTmpPermission.CanReset)
                            {
                                dtoTmpPermission.CanResetEditable = true;
                            }
                            if (dtoPermission.CanReset)
                            {
                                dtoTmpPermission.CanReset = true;
                            }
                        }
                        else
                        {
                            int moduleID = dtoPermission.ModuleID;//using to debug
                        }
                    }

                    data.Data.FactoryAccesses   = converter.DB2DTO_FactoryAccessList(context.User2Mng_FactoryAccess_View.Where(o => o.UserID == id).ToList());
                    data.Data.EmployeeFactories = converter.DB2DTO_EmployeeFactoryList(context.User2Mng_EmployeeFactory_View.Where(o => o.EmployeeID == data.Data.EmployeeID).ToList());
                }

                // decorate
                int index = 0;
                foreach (DTO.Permission dtoPermission in data.Data.Permissions.Where(o => o.ParentID == 0).OrderBy(o => o.DisplayOrder))
                {
                    dtoPermission.DisplayOrder = index;
                    index++;
                    foreach (DTO.Permission dtoSubPermission in data.Data.Permissions.Where(o => o.ParentID == dtoPermission.ModuleID).OrderBy(o => o.DisplayOrder))
                    {
                        dtoSubPermission.DisplayText  = "-----" + dtoSubPermission.DisplayText;
                        dtoSubPermission.DisplayOrder = index;
                        index++;
                    }
                }

                data.InternalCompanies   = supportFactory.GetInternalCompany().ToList();
                data.InternalDepartments = supportFactory.GetInternalDepartment().ToList();
                data.Locations           = supportFactory.GetLocation().ToList();
                data.UserGroups          = supportFactory.GetUserGroup().ToList();
                data.Managers            = supportFactory.GetEmployee().ToList();
                data.JobLevels           = supportFactory.GetJobLevel().ToList();
                data.Factories           = supportFactory.GetFactory().ToList();
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
            }

            return(data);
        }