// Update the records of a particular Partner Location public async Task <PartnerLocation> UpdatePartnerLocation(PartnerLocation partnerLocation) { mobDbContext.Entry(partnerLocation).State = EntityState.Modified; partnerLocation.LastUpdatedDate = DateTimeOffset.UtcNow; await mobDbContext.SaveChangesAsync().ConfigureAwait(false); return(await mobDbContext.PartnerLocations.FindAsync(partnerLocation.Id).ConfigureAwait(false)); }
public async Task <PartnerLocation> AddPartnerLocation(PartnerLocation partnerLocation) { if (partnerLocation.Id == Guid.Empty) { partnerLocation.Id = Guid.NewGuid(); } partnerLocation.CreatedDate = DateTimeOffset.UtcNow; partnerLocation.LastUpdatedByUserId = partnerLocation.CreatedByUserId; partnerLocation.LastUpdatedDate = DateTimeOffset.UtcNow; mobDbContext.PartnerLocations.Add(partnerLocation); await mobDbContext.SaveChangesAsync().ConfigureAwait(false); return(await mobDbContext.PartnerLocations.FindAsync(partnerLocation.Id).ConfigureAwait(false)); }
public async Task <IActionResult> UpdatePartnerLocation(PartnerLocation partnerLocation) { // Make sure the person adding the user is either an admin or already a user for the partner var currentUser = await userRepository.GetUserByNameIdentifier(User.FindFirst(ClaimTypes.NameIdentifier).Value).ConfigureAwait(false); if (!currentUser.IsSiteAdmin) { var currentUserPartner = partnerUserRepository.GetPartnerUsers().FirstOrDefault(pu => pu.PartnerId == partnerLocation.PartnerId && pu.UserId == currentUser.Id); if (currentUserPartner == null) { return(Forbid()); } } await partnerLocationRepository.UpdatePartnerLocation(partnerLocation).ConfigureAwait(false); return(Ok(partnerLocation)); }