Ejemplo n.º 1
0
        /// <inheritdoc/>
        public async Task <Hive> UpdateHiveAsync(int hiveId, UpdateHiveRequest updateRequest)
        {
            var dbHives = await _context.Hives.Where(p => p.Code == updateRequest.Code && p.Id != hiveId).ToArrayAsync().ConfigureAwait(false);

            if (dbHives.Length > 0)
            {
                throw new RequestedResourceHasConflictException("code");
            }

            dbHives = await _context.Hives.Where(p => p.Id == hiveId).ToArrayAsync().ConfigureAwait(false);

            if (dbHives.Length == 0)
            {
                throw new RequestedResourceNotFoundException();
            }

            var dbHive = dbHives[0];

            Mapper.Map(updateRequest, dbHive);
            dbHive.LastUpdatedBy = _userContext.UserId;

            await _context.SaveChangesAsync().ConfigureAwait(false);

            return(Mapper.Map <Hive>(dbHive));
        }
        /// <inheritdoc/>
        public async Task <Hive> UpdateHiveAsync(int hiveId, UpdateHiveRequest updateRequest)
        {
            var dbHive = await _context.Hives
                         .FirstOrDefaultAsync(p => p.Code == updateRequest.Code && p.Id != hiveId)
                         .ConfigureAwait(false);

            if (dbHive != null)
            {
                throw new RequestedResourceHasConflictException("code");
            }

            dbHive = await _context.Hives
                     .FirstOrDefaultAsync(s => s.Id == hiveId)
                     .ConfigureAwait(false);

            if (dbHive == null)
            {
                throw new RequestedResourceNotFoundException();
            }

            Mapper.Map(updateRequest, dbHive);
            dbHive.LastUpdatedBy = _userContext.UserId;

            await _context.SaveChangesAsync().ConfigureAwait(false);

            return(Mapper.Map <Hive>(dbHive));
        }
Ejemplo n.º 3
0
        /// <inheritdoc/>
        public async Task <Hive> UpdateHiveAsync(int hiveId, UpdateHiveRequest updateRequest)
        {
            var dbHives = await _context.Hives.Where(h => h.Code == updateRequest.Code && h.Id != hiveId).ToArrayAsync();

            if (dbHives.Length > 0)
            {
                throw new RequestedResourceHasConflictException("code");
            }

            dbHives = await _context.Hives.Where(h => h.Id == hiveId).ToArrayAsync();

            var dbHive = dbHives.FirstOrDefault();

            if (dbHives == null)
            {
                throw new RequestedResourceNotFoundException();
            }

            Mapper.Map(updateRequest, dbHive);
            dbHive.LastUpdatedBy = _userContext.UserId;

            await _context.SaveChangesAsync();

            return(Mapper.Map <Hive>(dbHive));
        }
Ejemplo n.º 4
0
        /// <inheritdoc/>
        public async Task <Hive> UpdateHiveAsync(int hiveId, UpdateHiveRequest updateRequest)
        {
            var dbHive = await GetExistingHiveAsync(hiveId).ConfigureAwait(false);

            await CheckExistingHiveCodeAsync(updateRequest.Code, h => h.Code == updateRequest.Code && h.Id != hiveId).ConfigureAwait(false);

            Mapper.Map(updateRequest, dbHive);
            dbHive.LastUpdatedBy = _userContext.UserId;

            await _context.SaveChangesAsync().ConfigureAwait(false);

            return(Mapper.Map <Hive>(dbHive));
        }
Ejemplo n.º 5
0
        /// <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));
        }
Ejemplo n.º 6
0
        /// <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);
        }
Ejemplo n.º 7
0
        /// <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));
        }