/// <inheritdoc /> public async Task DeleteHiveSectionAsync(int hiveSectionId) { DbHiveSection dbHiveSection = await GetDbHiveSectionById(hiveSectionId); if (dbHiveSection.IsDeleted == false) { throw new RequestedResourceHasConflictException( $"The hive section with id {hiveSectionId} hasn't got deleted status"); } _context.Sections.Remove(dbHiveSection); await _context.SaveChangesAsync(); }
/// <inheritdoc/> public async Task SetStatusAsync(int hiveSectionId, bool deletedStatus) { DbHiveSection dbHiveSection = await GetDbHiveSectionById(hiveSectionId); if (dbHiveSection.IsDeleted != deletedStatus) { dbHiveSection.IsDeleted = deletedStatus; dbHiveSection.LastUpdated = DateTime.UtcNow; dbHiveSection.LastUpdatedBy = _userContext.UserId; await _context.SaveChangesAsync(); } }
/// <inheritdoc/> public async Task <HiveSection> CreateHiveSectionAsync(UpdateHiveSectionRequest createRequest) { var dbHiveSections = await _context.Sections.Where(s => s.Code == createRequest.Code).ToArrayAsync(); if (dbHiveSections.Length > 0) { throw new RequestedResourceHasConflictException("code"); } DbHiveSection dbHiveSection = Mapper.Map <UpdateHiveSectionRequest, DbHiveSection>(createRequest); dbHiveSection.CreatedBy = _userContext.UserId; dbHiveSection.LastUpdatedBy = _userContext.UserId; _context.Sections.Add(dbHiveSection); await _context.SaveChangesAsync(); return(Mapper.Map <HiveSection>(dbHiveSection)); }
/// <inheritdoc /> public async Task <HiveSection> UpdateHiveSectionAsync(int hiveSectionId, UpdateHiveSectionRequest updateRequest) { DbHiveSection[] dbHiveSections = await _context.Sections .Where(p => p.Code == updateRequest.Code && p.Id != hiveSectionId).ToArrayAsync(); if (dbHiveSections.Length > 0) { throw new RequestedResourceHasConflictException($"The hive section with code {updateRequest.Code} exists"); } await CheckStoreHiveId(updateRequest); DbHiveSection dbHiveSection = await GetDbHiveSectionById(hiveSectionId); Mapper.Map(updateRequest, dbHiveSection); dbHiveSection.LastUpdatedBy = _userContext.UserId; await _context.SaveChangesAsync(); return(Mapper.Map <HiveSection>(dbHiveSection)); }
/// <inheritdoc /> public async Task <HiveSection> CreateHiveSectionAsync(UpdateHiveSectionRequest createRequest) { DbHiveSection[] dbHiveSections = await _context.Sections.Where(h => h.Code == createRequest.Code).ToArrayAsync(); if (dbHiveSections.Length > 0) { throw new RequestedResourceHasConflictException($"The hive section with code {createRequest.Code} exists"); } await CheckStoreHiveId(createRequest); DbHiveSection dbHiveSection = Mapper.Map <UpdateHiveSectionRequest, DbHiveSection>(createRequest); dbHiveSection.CreatedBy = _userContext.UserId; dbHiveSection.LastUpdatedBy = _userContext.UserId; _context.Sections.Add(dbHiveSection); await _context.SaveChangesAsync(); return(Mapper.Map <HiveSection>(dbHiveSection)); }