public async Task <IActionResult> NewProduct([FromBody] SaveSparePartResource model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var sparePart = new SparePart(model.Name, model?.Price, model?.RateOfTax, model.HsnSac, model.ProductId, model.StockInHand, model.OpeningDate, model.Model, model.Code, UserId); _sparePartRepository.Add(sparePart); await _unitOfWork.CompleteAsync(); return(Ok(_mapper.Map <SparePart, SparePartResource>(sparePart))); }
public async Task <IActionResult> UpdateProduct(int id, [FromBody] SaveSparePartResource model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var sparePartFromDb = await _sparePartRepository.GetAsync(id, UserId); if (sparePartFromDb == null) { return(NotFound()); } sparePartFromDb.Modify(model.Name, model?.Price, model?.RateOfTax, model.HsnSac, model.ProductId, model.StockInHand, model.OpeningDate, model.Model, model.Code); await _unitOfWork.CompleteAsync(); return(Ok(_mapper.Map <SparePart, SparePartResource>(sparePartFromDb))); }