private async Task <IActionResult> AddOrUpdateAdministrator(GroupAdministratorItems user, string slug, string emailAddress, string businessId) { var repository = _groupRepository(_createConfig(businessId)); var existingGroup = await repository.GetContentfulGroup(slug); existingGroup.GroupAdministrators.Items = existingGroup.GroupAdministrators.Items.Where(a => a.Email != emailAddress).ToList(); if (user != null) { existingGroup.GroupAdministrators.Items.Add(user); ManagementGroup managementGroup = new ManagementGroup(); _mapper.Map(existingGroup, managementGroup); return(await _handler.Get(async() => { var managementRepository = _managementRepository(_createConfig(businessId)); var version = await managementRepository.GetVersion(existingGroup.Sys.Id); existingGroup.Sys.Version = version; var response = await managementRepository.CreateOrUpdate(managementGroup, existingGroup.Sys); return response.StatusCode == System.Net.HttpStatusCode.OK ? HttpResponse.Successful($"Successfully updated the group {existingGroup.Name}") : HttpResponse.Failure(response.StatusCode, "An error has occurred"); })); } else { throw new Exception("Invalid data received"); } }
public async Task <IActionResult> AddAdministrator([FromBody] GroupAdministratorItems user, string slug, string emailAddress, string businessId) { return(await AddOrUpdateAdministrator(user, slug, emailAddress, businessId)); }