Exemple #1
0
 public static MediaAndProductionOrder ToMediaAndProductionOrder(this MediaOrderDto mediaOrderDto)
 {
     return(new MediaAndProductionOrder
     {
         PrintingType = mediaOrderDto.PrintingType,
         DeliveryAddress = mediaOrderDto.DeliveryAddress,
         DocumentPath = mediaOrderDto.DocumentPath,
         ExtraDetail = mediaOrderDto.ExtraDetail,
         NumberOfPages = mediaOrderDto.NumberOfPages,
     });
 }
        public async Task <MediaAndProductionOrder> CreateMediaOrder(int productId, string userId, MediaOrderDto mediaOrderDto)
        {
            try
            {
                Product productToBeOrdered = await _context.Products.FirstOrDefaultAsync(p => p.Id == productId);

                if (productToBeOrdered != null)
                {
                    MediaAndProductionOrder mediaAndProductionOrder = mediaOrderDto.ToMediaAndProductionOrder();
                    _context.MediaAndProductionOrders.Add(mediaAndProductionOrder);
                    if (await _context.SaveChangesAsync() > 0)
                    {
                        return(mediaAndProductionOrder);
                    }
                    return(null);
                }
                return(null);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.InnerException.ToString());
                return(null);
            }
        }