Click here to Skip to main content
15,891,905 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I already have a CRUD API and I want to make another API that deals with the creation of the OfficeInvoice table. The behavior I want to see is that when the OfficeInvoice is created, it updates the MedicineStore table to increment the quantity for the MedicineStore you purchased/are purchasing as ypu can see the route for creat make the officeinvoice and same time call the getById to get the record that created same like this is it possible to make it but with update after create?


What I have tried:

public class Medicine
    {
        public int MedicineId { get; set; }
        public string MedicineName { get; set; }
        public string Company { get; set; }
        public float Price { get; set; }
        public int Quantity { get; set; }
        public string Code { get; set; }
        public int SDrugId { get; set; }
        public ScientificDrug ScientificDrug { get; set; }
        public ICollection<CustomerInvoice> CustomerInvoices { get; set; }
       = new List<CustomerInvoice>();
        public ICollection<MedicineReturn> MedicineReturns { get; set; }
      = new List<MedicineReturn>();
        public int DrugStoreId { get; set; }
        public DrugStores DrugStores { get; set; }
        public ICollection<OfficeInvoice> OfficeInvoices { get; set; }
   = new List<OfficeInvoice>();
        public ICollection<OfficeReturn> OfficeReturns { get; set; }
    = new List<OfficeReturn>();
    }

public class OfficeInvoice
    {
        public int OfficeInvoiceId { get; set; }
        public int Quantity { get; set; }
        public float Discount { get; set; }
        public float TotalPrice { get; set; }
        public Medicine Medicine { get; set; }
        public int MediccineId { get; set; }
        public BuyInvoice BuyInvoice { get; set; }
        public int BuyInvoiceId { get; set; }
    }


public async Task<IActionResult> CreateOfficeInvoice([FromBody] OfficeInvoiceForCreate officeInvoiceForCreate)
     {
         var oinvoice = _mapper.Map<OfficeInvoice>(officeInvoiceForCreate);
         _OInvoiceRepository.CreateOfficeInvoice(oinvoice);
         await _OInvoiceRepository.SaveChanges();
         await _OInvoiceRepository.GetOfficeInvoiceById(oinvoice.OfficeInvoiceId);
         return CreatedAtRoute("GetOfficeInvoice", new { id = oinvoice.OfficeInvoiceId }, oinvoice);
     }
Posted
Updated 5-Aug-20 18:23pm

1 solution

Unless
Quote:
CreateOfficeInvoice
is automatically generated, why can't you add code here to do what you wish (since it seems you have everything you need here already) - you need the CreateOfficeInvoice to succeed, but after that the world's your oyster.

I guess there has to be some sort of referential integrity here ... can
public ICollection<CustomerInvoice> CustomerInvoices { get; set; } = new List<CustomerInvoice>();
be an observableCollection maybe ? that way adding a new CustomerInvoice automatically triggers updating of the MedicineStore table
 
Share this answer
 
Comments
Anas92 6-Aug-20 8:01am    
sorry sir can you explan little more what you mean?
thank you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900