private static List <BillingSparePartItem> BillingSparePartItems(SaveBillingSparePartResource model)
 {
     return(model.BillingSparePartItems.Select(item => BillingSparePartItem.Add(item.ProductId,
                                                                                item.Quantity, item.Discount, item.Rate, item.TaxableValue,
                                                                                item.HsnCode, item.IgstAmount, item.CgstAmount, item.SgstAmount, item.Total))
            .ToList());
 }
        public async Task <IActionResult> CreateOrder([FromBody] SaveBillingSparePartResource model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }


            var newBillingSparePart = new BillingSparePart(model.CustomerName, model.Date,
                                                           model.CustomerState, model.CustomerGstin, model.CustomerContact,
                                                           model.PlaceOfSupply, model.TotalInvoiceValue, UserId, BillingSparePartItems(model));

            _billingSparePartRepository.Add(newBillingSparePart);
            await _unitOfWork.CompleteAsync();

            return(StatusCode(201));
        }
        public async Task <IActionResult> UpdateOrder(int id, [FromBody] SaveBillingSparePartResource model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var orderFromDb = await FindOrderById(id);

            if (orderFromDb == null)
            {
                return(NotFound());
            }

            orderFromDb.Modify(model.CustomerName, model.Date,
                               model.CustomerState, model.CustomerGstin, model.CustomerContact,
                               model.PlaceOfSupply, model.TotalInvoiceValue, BillingSparePartItems(model));
            await _unitOfWork.CompleteAsync();



            return(Ok(_mapper.Map <BillingSparePart, BillingSparePartResource>(orderFromDb)));
        }