/// <inheritdoc/> public async Task <HiveSection> CreateHiveSectionAsync(int hiveId, UpdateHiveSectionRequest createRequest) { var dbHiveSection = await _context.Sections .FirstOrDefaultAsync(h => h.Code == createRequest.Code) .ConfigureAwait(false); if (dbHiveSection != null) { throw new RequestedResourceHasConflictException("code"); } var dbHive = await _context.Hives .FirstOrDefaultAsync(x => x.Id == hiveId) .ConfigureAwait(false); if (dbHive == null) { throw new RequestedResourceNotFoundException(); } var hiveSection = Mapper.Map <UpdateHiveSectionRequest, DbHiveSection>(createRequest); hiveSection.StoreHiveId = hiveId; hiveSection.CreatedBy = _userContext.UserId; hiveSection.LastUpdatedBy = _userContext.UserId; hiveSection.Created = DateTime.Now; hiveSection.LastUpdated = DateTime.Now; _context.Sections.Add(hiveSection); await _context.SaveChangesAsync().ConfigureAwait(false); return(Mapper.Map <HiveSection>(hiveSection)); }
/// <inheritdoc/> public async Task <HiveSection> CreateHiveSectionAsync(UpdateHiveSectionRequest createRequest) { var dbSections = await _context.Sections.Where(s => s.Code == createRequest.Code).ToArrayAsync(); if (dbSections.Length > 0) { throw new RequestedResourceHasConflictException("code"); } var dbHives = await _context.Hives.Where(h => h.Id == createRequest.HiveId).ToArrayAsync(); if (dbHives.Length == 0) { throw new RequestedResourceNotFoundException("hiveId"); } var dbHiveId = dbHives[0].Id; var dbSection = Mapper.Map <UpdateHiveSectionRequest, DbHiveSection>(createRequest); dbSection.CreatedBy = _userContext.UserId; dbSection.LastUpdatedBy = _userContext.UserId; _context.Sections.Add(dbSection); await _context.SaveChangesAsync(); return(Mapper.Map <HiveSection>(dbSection)); }
/// <inheritdoc/> public async Task <Hive> CreateHiveAsync(UpdateHiveRequest createRequest) { await CheckExistingHiveCodeAsync(createRequest.Code, h => h.Code == createRequest.Code).ConfigureAwait(false); var dbHive = Mapper.Map <UpdateHiveRequest, DbHive>(createRequest); dbHive.CreatedBy = _userContext.UserId; dbHive.LastUpdatedBy = _userContext.UserId; _context.Hives.Add(dbHive); await _context.SaveChangesAsync().ConfigureAwait(false); return(Mapper.Map <Hive>(dbHive)); }
/// <inheritdoc/> public async Task <HiveSection> CreateHiveSectionAsync(UpdateHiveSectionRequest createRequest) { await CheckExistingHiveSectionCodeAsync(createRequest.Code, s => s.Code == createRequest.Code).ConfigureAwait(false); var dbHiveSection = Mapper.Map <UpdateHiveSectionRequest, DbHiveSection>(createRequest); dbHiveSection.CreatedBy = _userContext.UserId; dbHiveSection.LastUpdatedBy = _userContext.UserId; _context.Sections.Add(dbHiveSection); await _context.SaveChangesAsync().ConfigureAwait(false); return(Mapper.Map <DbHiveSection, HiveSection>(dbHiveSection)); }
/// <inheritdoc/> public async Task<Hive> CreateHiveAsync(UpdateHiveRequest createRequest) { var dbHives = await _context.Hives.Where(h => h.Code == createRequest.Code).ToArrayAsync(); if (dbHives.Length > 0) { throw new RequestedResourceHasConflictException("code"); } var dbHive = Mapper.Map<UpdateHiveRequest, DbHive>(createRequest); dbHive.CreatedBy = _userContext.UserId; dbHive.LastUpdatedBy = _userContext.UserId; _context.Hives.Add(dbHive); await _context.SaveChangesAsync(); return Mapper.Map<Hive>(dbHive); }
/// <inheritdoc/> public async Task SetStatusAsync(int hiveSectionId, bool deletedStatus) { var dbHiveSections = await _context.Sections.Where(h => h.Id == hiveSectionId).ToArrayAsync(); if (dbHiveSections.Length == 0) { throw new RequestedResourceNotFoundException(); } var dbHiveSection = dbHiveSections[0]; dbHiveSection.IsDeleted = deletedStatus; dbHiveSection.LastUpdatedBy = _userContext.UserId; await _context.SaveChangesAsync(); }
/// <inheritdoc/> public async Task SetStatusAsync(int hiveSectionId, bool deletedStatus) { var dbHiveSection = await _context.Sections.FirstOrDefaultAsync(x => x.Id == hiveSectionId).ConfigureAwait(false); if (dbHiveSection == null) { throw new RequestedResourceNotFoundException(Resources.HiveSectionNotFound); } if (dbHiveSection.IsDeleted != deletedStatus) { dbHiveSection.IsDeleted = deletedStatus; dbHiveSection.LastUpdated = DateTime.UtcNow; dbHiveSection.LastUpdatedBy = _userContext.UserId; await _context.SaveChangesAsync().ConfigureAwait(false); } }
/// <inheritdoc/> public async Task SetStatusAsync(int hiveSectionId, bool deletedStatus) { var dbCategories = await _context.Sections.Where(c => hiveSectionId == c.Id).ToArrayAsync(); if (dbCategories.Length == 0) { throw new RequestedResourceNotFoundException(); } var dbCategory = dbCategories[0]; if (dbCategory.IsDeleted != deletedStatus) { dbCategory.IsDeleted = deletedStatus; dbCategory.LastUpdated = DateTime.UtcNow; dbCategory.LastUpdatedBy = _userContext.UserId; await _context.SaveChangesAsync(); } }
/// <inheritdoc/> public async Task SetStatusAsync(int hiveSectionId, bool deletedStatus) { var dbHiveSections = await _context.Sections.Where(s => s.Id == hiveSectionId).ToArrayAsync(); if (dbHiveSections.Length == 0) { throw new RequestedResourceNotFoundException($"Hive section not found in {nameof(SetStatusAsync)}"); } var dbHiveSection = dbHiveSections[0]; 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().ConfigureAwait(false); if (dbHiveSections.Length > 0) { throw new RequestedResourceHasConflictException("code"); } var dbHiveSection = Mapper.Map <UpdateHiveSectionRequest, DbHiveSection>(createRequest); dbHiveSection.CreatedBy = _userContext.UserId; dbHiveSection.LastUpdatedBy = _userContext.UserId; _context.Sections.Add(dbHiveSection); await _context.SaveChangesAsync().ConfigureAwait(false); return(Mapper.Map <DbHiveSection, HiveSection>(dbHiveSection)); }
/// <inheritdoc/> public async Task <Hive> CreateHiveAsync(UpdateHiveRequest createRequest) { var dbHives = await _context.Hives.FirstOrDefaultAsync(h => h.Code == createRequest.Code).ConfigureAwait(false); if (dbHives != null) { throw new RequestedResourceHasConflictException("code"); } var dbHive = Mapper.Map <UpdateHiveRequest, DbHive>(createRequest); dbHive.CreatedBy = _userContext.UserId; dbHive.LastUpdatedBy = _userContext.UserId; _context.Hives.Add(dbHive); await _context.SaveChangesAsync().ConfigureAwait(false); return(Mapper.Map <Hive>(dbHive)); }
/// <inheritdoc/> public async Task SetStatusAsync(int hiveSectionId, bool deletedStatus) { var dbSections = await _context.Sections.Where(section => hiveSectionId == section.Id).ToArrayAsync().ConfigureAwait(false); if (dbSections.Length == 0) { throw new RequestedResourceNotFoundException(); } var dbHiveSection = dbSections[0]; 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) { 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)); }