//public List<OrganizationPostDTO> ToOrganizationPostDTOList(IQueryable<OrganizationPost> posts) //{ // List<OrganizationPostDTO> result = new List<OrganizationPostDTO>(); // foreach (var item in posts) // { // var RoleDto = ToOrganizationPostDTO(item); // result.Add(RoleDto); // } // return result; //} public OrganizationPostDTO ToOrganizationPostDTO(OrganizationPost item) { OrganizationPostDTO result = new OrganizationPostDTO(); result.ID = item.ID; result.ExternalKey = item.ExternalKey; result.Name = item.Name; result.CurrentUserID = item.UserID ?? 0; if (result.CurrentUserID != 0) { BizUser bizUser = new MyModelManager.BizUser(); result.CurrentUser = bizUser.GetUser(result.CurrentUserID); result.Name += " / " + result.CurrentUser.FullName; result.CurrentUserExternalKey = result.CurrentUser.ExternalKey; } result.OrganizationID = item.OrganizationID; result.OrganizationName = item.Organization.Name; result.OrganizationExternalKey = item.Organization.ExternalKey; result.OrganizationTypeID = item.Organization.OrganizationTypeID; result.OrganizationTypeExternalKey = item.Organization.OrganizationType.ExternalKey; result.OrganizationTypeRoleTypeID = item.OrganizationType_RoleTypeID; result.OrganizationTypeRoleTypeExternalKey = item.OrganizationType_RoleType.ExternalKey; result.RoleTypeID = item.OrganizationType_RoleType.RoleTypeID; result.RoleTypeExternalKey = item.OrganizationType_RoleType.RoleType.ExternalKey; result.IsAdmin = item.OrganizationType_RoleType.IsAdmin == true; result.IsSuperAdmin = item.OrganizationType_RoleType.RoleType.IsSuperAdmin == true; return(result); }
public OrganizationPostDTO ToOrganizationPostDTO(OrganizationPost item) { OrganizationPostDTO result = new OrganizationPostDTO(); result.ID = item.ID; result.Name = item.Name; return(result); }
public void SaveOrganization(OrganizationDTO organizationDto) { using (var context = new MyProjectEntities()) { Organization dbOrganization = null; if (organizationDto.ID == 0) { dbOrganization = new Organization(); dbOrganization.SecuritySubject = new SecuritySubject(); dbOrganization.SecuritySubject.Type = (int)SecuritySubjectType.Organization; } else { dbOrganization = context.Organization.First(x => x.ID == organizationDto.ID); } dbOrganization.Name = organizationDto.Name; dbOrganization.ExternalKey = organizationDto.ExternalKey; dbOrganization.OrganizationTypeID = organizationDto.OrganizationTypeID; List <OrganizationPost> removedItems = new List <OrganizationPost>(); foreach (var post in dbOrganization.OrganizationPost) { if (!organizationDto.OrganizationPosts.Any(x => x.ID == post.ID)) { removedItems.Add(post); } } foreach (var item in removedItems.ToList()) { context.OrganizationPost.Remove(item); } foreach (var post in organizationDto.OrganizationPosts) { var dbPost = dbOrganization.OrganizationPost.FirstOrDefault(x => post.ID != 0 && x.ID == post.ID); if (dbPost == null) { dbPost = new OrganizationPost(); dbOrganization.OrganizationPost.Add(dbPost); dbPost.SecuritySubject = new SecuritySubject(); dbPost.SecuritySubject.Type = (int)SecuritySubjectType.OrganizationPost; } dbPost.Name = post.Name; dbPost.ExternalKey = post.ExternalKey; dbPost.UserID = post.CurrentUserID; dbPost.OrganizationType_RoleTypeID = post.OrganizationTypeRoleTypeID; } if (dbOrganization.ID == 0) { context.Organization.Add(dbOrganization); } context.SaveChanges(); } }
public async Task <IActionResult> SetStaff([FromBody] OrganizationPost model) { if (model == null) { return(StatusCode(502)); } string endpointUrl = "vsd_SetCPUOrgContracts"; string modelString = System.Text.Json.JsonSerializer.Serialize(model); modelString = Helpers.Helpers.updateFortunecookieBindNull(modelString); modelString = Helpers.Helpers.removeNullsForStaffUpdate(modelString); DynamicsResult result = await _dynamicsResultService.Post(endpointUrl, modelString); return(StatusCode((int)result.statusCode, result.result.ToString())); }
public void SaveOrganization(OrganizationDTO organizationDto) { using (var context = new MyProjectEntities()) { Organization dbOrganization = null; if (organizationDto.ID == 0) { dbOrganization = new Organization(); } else { dbOrganization = context.Organization.First(x => x.ID == organizationDto.ID); } dbOrganization.Name = organizationDto.Name; dbOrganization.OrganizationTypeID = organizationDto.OrganizationTypeID; //چیزی حذف نمیشود foreach (var post in organizationDto.OrganizationPosts) { var dbPost = dbOrganization.OrganizationPost.FirstOrDefault(x => x.ID == post.ID); if (dbPost == null) { dbPost = new OrganizationPost(); dbOrganization.OrganizationPost.Add(dbPost); dbPost.SecuritySubject.Add(new SecuritySubject()); } dbPost.Name = post.Name; dbPost.UserID = post.CurrentUserID; dbPost.OrganizationType_RoleTypeID = post.OrganizationTypeRoleTypeID; } if (dbOrganization.ID == 0) { context.Organization.Add(dbOrganization); } context.SaveChanges(); } }
public void CheckAdminUserExists() { var context = new MyProjectEntities(); if (!context.User.Any(x => x.OrganizationPost.Any(y => y.OrganizationType_RoleType.RoleType.IsSuperAdmin == true))) { var user = new User(); user = new User(); user.FirstName = "راهبر"; user.LastName = "ارشد"; user.UserName = "******"; user.Password = "******"; var organizationPost = context.OrganizationPost.FirstOrDefault(x => x.OrganizationType_RoleType.RoleType.IsSuperAdmin == true); if (organizationPost == null) { organizationPost = new OrganizationPost(); organizationPost.Name = "پست راهبر ارشد"; var organization = context.Organization.FirstOrDefault(x => x.OrganizationType.OrganizationType_RoleType.Any(y => y.RoleType.IsSuperAdmin == true)); OrganizationType organizationType = null; if (organization == null) { organization = new Organization(); organization.Name = "سازمان"; organizationType = context.OrganizationType.FirstOrDefault(x => x.OrganizationType_RoleType.Any(y => y.RoleType.IsSuperAdmin == true)); if (organizationType == null) { organizationType = new OrganizationType(); organizationType.Name = "نوع سازمان"; organizationType.SecuritySubject = new SecuritySubject() { Type = (int)SecuritySubjectType.OrganizationType }; context.OrganizationType.Add(organizationType); } organization.OrganizationType = organizationType; organization.SecuritySubject = new SecuritySubject() { Type = (int)SecuritySubjectType.Organization }; context.Organization.Add(organization); } var organizationTypeRoleType = context.OrganizationType_RoleType.FirstOrDefault(x => x.OrganizationTypeID == organizationType.ID && x.RoleType.IsSuperAdmin == true); if (organizationTypeRoleType == null) { organizationTypeRoleType = new OrganizationType_RoleType(); organizationTypeRoleType.OrganizationType = organizationType; var superAdminRoleType = context.RoleType.FirstOrDefault(x => x.IsSuperAdmin == true); if (superAdminRoleType == null) { superAdminRoleType = new RoleType(); superAdminRoleType.Name = "راهبر ارشد"; superAdminRoleType.IsSuperAdmin = true; superAdminRoleType.SecuritySubject = new SecuritySubject() { Type = (int)SecuritySubjectType.RoleType }; context.RoleType.Add(superAdminRoleType); } organizationTypeRoleType.RoleType = superAdminRoleType; organizationTypeRoleType.SecuritySubject = new SecuritySubject() { Type = (int)SecuritySubjectType.OrganizationTypeRoleType }; context.OrganizationType_RoleType.Add(organizationTypeRoleType); } organizationPost.Organization = organization; organizationPost.OrganizationType_RoleType = organizationTypeRoleType; organizationPost.SecuritySubject = new SecuritySubject() { Type = (int)SecuritySubjectType.OrganizationPost }; context.OrganizationPost.Add(organizationPost); } user.OrganizationPost.Add(organizationPost); context.User.Add(user); context.SaveChanges(); } }