Beispiel #1
0
        /// <inheritdoc/>
        public async Task <Delivery> UpdateDeliveryAsync(int deliveryId, UpdateDeliveryRequest updateRequest)
        {
            var dbDeliveries = await _context.Deliveries.Where(o => o.Address == updateRequest.Address).ToArrayAsync();

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

            dbDeliveries = await _context.Deliveries.Where(o => o.DeliveryId == deliveryId).ToArrayAsync();

            var dbDelivery = dbDeliveries.FirstOrDefault();

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

            Mapper.Map(updateRequest, dbDelivery);
            //dbOrder.LastUpdatedBy = _userContext.UserId;

            await _context.SaveChangesAsync();

            return(Mapper.Map <Delivery>(dbDelivery));
        }
Beispiel #2
0
        /// <inheritdoc/>
        public async Task <Delivery> CreateDeliveryAsync(UpdateDeliveryRequest createRequest)
        {
            var dbDeliveries = await _context.Deliveries.Where(h => h.Address == createRequest.Address).ToArrayAsync();

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

            var dbDelivery = Mapper.Map <UpdateDeliveryRequest, DbDelivery>(createRequest);

            _context.Deliveries.Add(dbDelivery);

            await _context.SaveChangesAsync();

            return(Mapper.Map <Delivery>(dbDelivery));
        }