public JsonResult GetNir(int nirId) { try { NirModel nirs = nirRepository.All().FirstOrDefault(x => x.Id == nirId); nirs.Items = nirItemRepository.All().Where(x => x.NirId == nirs.Id).ToList(); return(Json(nirs)); } catch (Exception e) { return(Json(e.ToString())); } }
public IActionResult AddNir([FromBody] NirModel model) { if (ModelState.IsValid) { nirRepository.Insert(model); foreach (NirItemsModel prod in model.Items) { var incProdStoc = productRepository.All().FirstOrDefault(product => product.Name == prod.Name); incProdStoc.Stoc += prod.Quantity; _context.SaveChanges(); } return(Json(new { error = false, message = "Sales saved successfully" })); } return(Json(new { error = true, message = "failed to save Sales" })); }
public IActionResult EditNir(NirModel model) { if (model != null) { var items = nirItemRepository.All().Where(x => x.NirId == model.Id).ToList(); if (items.Any()) { foreach (var item in items) { nirItemRepository.Delete(item); } } var nir = nirRepository.Find(model.Id); nir.Notes = model.Notes; nir.PaymentMethod = model.PaymentMethod; nir.NirCode = model.NirCode; nir.SupplierId = model.SupplierId; nir.Total = model.Total; nir.NirDate = model.NirDate; nir.Status = model.Status; nir.Discount = model.Discount; nir.GrandTotal = model.GrandTotal; foreach (var item in model.Items) { nir.Items.Add(new NirItemsModel { Price = item.Price, Amount = item.Amount, Quantity = item.Quantity, Name = item.Name }); } nirRepository.Update(nir, model.Id); return(Json(new { error = false, message = "Nota intrare Receptie actualizata cu succes!" })); } return(Json(new { error = true, message = "Esuare actualizare Nota Intrare Receptie!" })); }