public async Task <OrderDetailDTO> CreateOrUpdateOrderDetailAsync(OrderDetailDTO orderDetail)
        {
            OrderDetail entity;

            if (orderDetail.Id > 0)
            {
                entity = await _orderDetailRepository.GetByIdAsync(orderDetail.Id, false);

                if (entity == null)
                {
                    throw new AppException("Purchase Order Detail Not Found");
                }

                entity = Mapper.Map(orderDetail, entity);

                //entity = Mapper.Map<OrderDetail>(orderDetail);

                _orderDetailRepository.Update(entity);
            }
            else
            {
                entity = Mapper.Map <OrderDetail>(orderDetail);
                _orderDetailRepository.Insert(entity);
            }

            await UnitOfWork.SaveChangesAsync();

            var rs = Mapper.Map <OrderDetailDTO>(entity);

            return(rs);
        }
        public async Task <ProgressCheckDto> CreateOrUpdatePurchaseOrderAsync(ProgressCheckDto rq)
        {
            ProgressCheck entity = new ProgressCheck();

            if (rq.Id > 0)
            {
                entity = await _progresscheckRepository.GetByIdAsync(rq.Id, false);

                if (entity == null)
                {
                    throw new AppException("Progress Check Not Found");
                }

                //entity = Mapper.Map(rq, entity);
                entity.InspectionDate   = rq.InspectionDate;
                entity.IntendedShipDate = rq.IntendedShipDate;
                decimal temp = 0;
                rq.ListOrderDetail = Mapper.Map <List <OrderDetail> >(rq.ListOrderDetailDto);
                foreach (var item in rq.ListOrderDetail)
                {
                    temp += item.ReviseQuantity;
                    OrderDetail orderDetail = await _orderdetailRepository.GetByIdAsync(item.Id, false);

                    orderDetail.ReviseQuantity = item.ReviseQuantity;
                    _orderdetailRepository.Update(orderDetail);
                }
                entity.EstQtyToShip = temp;
                if (entity.EstQtyToShip == rq.POQuantity)
                {
                    entity.Complete = true;
                }
                else
                {
                    entity.Complete = false;
                }
                _progresscheckRepository.Update(entity);
            }
            else
            {
                entity.InspectionDate = rq.InspectionDate;

                decimal temp = 0;
                foreach (var item in rq.ListOrderDetail)
                {
                    temp += item.ReviseQuantity;
                    OrderDetail orderDetail = await _orderdetailRepository.GetByIdAsync(item.Id, false);

                    orderDetail.ReviseQuantity = item.ReviseQuantity;
                    _orderdetailRepository.Update(orderDetail);
                }
                entity.EstQtyToShip = temp;
                if (entity.EstQtyToShip == rq.POQuantity)
                {
                    entity.Complete = true;
                }
                else
                {
                    entity.Complete = false;
                }
                _progresscheckRepository.Insert(entity);
            }

            await UnitOfWork.SaveChangesAsync();

            var rs = Mapper.Map <ProgressCheckDto>(entity);

            return(rs);
        }
示例#3
0
        public async Task <ProgressCheckDto> CreateOrUpdateProgressCheckAsync(ProgressCheckDto rq)
        {
            ProgressCheck entity = new ProgressCheck();

            //rq.ListOrderDetail = Mapper.Map<List<OrderDetail>>(rq.ListOrderDetailDto);
            if (rq.Id > 0)
            {
                entity = await _progresscheckRepository.GetByIdAsync(rq.Id, false);

                Order order = await _orderRepository.GetByIdAsync(entity.OrderId, false);

                if (entity == null)
                {
                    throw new AppException("Progress Check Not Found");
                }
                if (rq.selected == true)
                {
                    entity.InspectionDate   = rq.InspectionDate;
                    entity.IntendedShipDate = rq.IntendedShipDate;
                }
                decimal temp = 0;

                foreach (var item in rq.ListOrderDetailDto)
                {
                    OrderDetail orderDetail = await _orderdetailRepository.GetByIdAsync(item.Id, false);

                    if (item.selected == true)
                    {
                        temp += item.ReviseQuantity;
                        orderDetail.ReviseQuantity = item.ReviseQuantity;
                        if (orderDetail.Quantity == item.ReviseQuantity)
                        {
                            orderDetail.Status = OrderStatus.AwaitingBooking;
                        }
                        _orderdetailRepository.Update(orderDetail);
                    }
                    else
                    {
                        temp += orderDetail.ReviseQuantity;
                    }
                }
                entity.EstQtyToShip = temp;
                if (entity.EstQtyToShip == rq.POQuantity)
                {
                    entity.Complete = true;
                    order.Status    = OrderStatus.AwaitingBooking;
                }
                else
                {
                    entity.Complete = false;
                }
                _orderRepository.Update(order);
                _progresscheckRepository.Update(entity);
            }
            else
            {
                entity.InspectionDate   = rq.InspectionDate;
                entity.IntendedShipDate = rq.IntendedShipDate;
                entity.OrderId          = rq.OrderId;
                Order order = await _orderRepository.GetByIdAsync(rq.OrderId, false);

                decimal temp = 0;
                foreach (var item in rq.ListOrderDetailDto)
                {
                    OrderDetail orderDetail = await _orderdetailRepository.GetByIdAsync(item.Id, false);

                    if (item.selected == true)
                    {
                        temp += item.ReviseQuantity;
                        orderDetail.ReviseQuantity = item.ReviseQuantity;
                        if (orderDetail.Quantity == item.ReviseQuantity)
                        {
                            orderDetail.Status = OrderStatus.AwaitingBooking;
                        }
                        _orderdetailRepository.Update(orderDetail);
                    }
                    else
                    {
                        item.ReviseQuantity = orderDetail.ReviseQuantity;
                    }
                }
                entity.EstQtyToShip = temp;
                if (entity.EstQtyToShip == rq.POQuantity)
                {
                    entity.Complete = true;
                    order.Status    = OrderStatus.AwaitingBooking;
                }
                else
                {
                    entity.Complete = false;
                }
                _orderRepository.Update(order);
                _progresscheckRepository.Insert(entity);
            }

            await UnitOfWork.SaveChangesAsync();

            var rs = rq;

            rs.Complete     = entity.Complete;
            rs.EstQtyToShip = entity.EstQtyToShip;
            rs.ShipDate     = rq.ShipDate;
            rs.Supplier     = rq.Supplier;
            rs.Factory      = rq.Factory;
            rs.Id           = entity.Id;
            return(rs);
        }
 public async Task <OrderDetail> GetByIdAsync(int id)
 {
     return(await _orderDetailRepository.GetByIdAsync(id));
 }