public async Task <CommandeFournisseurEntity> UpdateAsync(CommandeFournisseurEntity item) { _context.Update(item); await _context.SaveChangesAsync(); return(item); }
// ARTICLES public async Task <CommandeFournisseurLigneEntity> AddArticle(CommandeFournisseurEntity commande_fournisseur, ArticleEntity article, int article_quantite) { /* * delegation service CommandeFournisseurLigne */ return(await _service_ligne.AddArticle(commande_fournisseur, article, article_quantite)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Numero,Commentaire,FournisseurId,NomCommandeFournisseurStatutId")] CommandeFournisseurEntity commandeFournisseurEntity) { if (ModelState.IsValid) { try { await _service_commande_fournisseur.Update(commandeFournisseurEntity); } catch (DbUpdateConcurrencyException) { if (!CommandeFournisseurEntityExists(commandeFournisseurEntity.Id)) { return(NotFound()); } else { throw; } } ViewData["FournisseurId"] = new SelectList(_context.FournisseurEntities, "Id", "Raison", commandeFournisseurEntity.FournisseurId); ViewData["ArticleId"] = new SelectList(await _service_article.getAllByFournisseurId(commandeFournisseurEntity.FournisseurId), "Id", "Libelle"); return(View(commandeFournisseurEntity)); } ViewData["FournisseurId"] = new SelectList(_context.FournisseurEntities, "Id", "Id", commandeFournisseurEntity.FournisseurId); ViewData["NomCommandeFournisseurStatutId"] = new SelectList(_context.NomCommandeFournisseurStatutEntities, "Id", "Code", commandeFournisseurEntity.NomCommandeFournisseurStatutId); return(View(commandeFournisseurEntity)); }
public async Task <CommandeFournisseurEntity> ValidateAsync(CommandeFournisseurEntity item) { item.NomCommandeFournisseurStatutId = _context.NomCommandeFournisseurStatutEntities.Where(o => o.Code == "T").FirstOrDefault().Id; // A = Transmise au transporteur _context.Update(item); await _context.SaveChangesAsync(); return(item); }
public async Task <CommandeFournisseurEntity> DeleteAsync(CommandeFournisseurEntity item) { item.IsDeleted = true; _context.Update(item); await _context.SaveChangesAsync(); return(item); }
public async Task <CommandeFournisseurEntity> AddAsync(CommandeFournisseurEntity item) { item.NomCommandeFournisseurStatutId = _context.NomCommandeFournisseurStatutEntities.Where(o => o.Code == "C").FirstOrDefault().Id; // A = création _context.CommandeFournisseurEntities.Add(item); await _context.SaveChangesAsync(); return(item); }
public async Task <CommandeFournisseurEntity> Validate(CommandeFournisseurEntity item) { if (!_repository.Exist(item.Id)) { throw new NotFoundException(ExceptionMessageUtil.NOT_FOUND); } return(await _repository.ValidateAsync(item)); }
public async Task <IActionResult> Create([Bind("Id,Numero,Commentaire,FournisseurId")] CommandeFournisseurEntity commandeFournisseurEntity) { if (ModelState.IsValid) { await _service_commande_fournisseur.Add(commandeFournisseurEntity); return(RedirectToAction("Edit", new { Id = commandeFournisseurEntity.Id })); } ViewData["FournisseurId"] = new SelectList(_context.FournisseurEntities, "Id", "Id", commandeFournisseurEntity.FournisseurId); ViewData["NomCommandeFournisseurStatutId"] = new SelectList(_context.NomCommandeFournisseurStatutEntities, "Id", "Code", commandeFournisseurEntity.NomCommandeFournisseurStatutId); return(View(commandeFournisseurEntity)); }
// ANNULATION public async Task <IActionResult> StatutAnnulation(int id) { CommandeFournisseurEntity commande_fournisseur = await _service_commande_fournisseur.GetOneById(id); if (commande_fournisseur != null) { commande_fournisseur.NomCommandeFournisseurStatut = await _context.NomCommandeFournisseurStatutEntities.Where(o => o.Code == "A").FirstOrDefaultAsync(); await _service_commande_fournisseur.Update(commande_fournisseur); } return(RedirectToAction(nameof(Dashboard), new { filtre = "A" })); }
public async Task <CommandeFournisseurEntity> UploadStock(CommandeFournisseurEntity item) { if (!_repository.Exist(item.Id)) { throw new NotFoundException(ExceptionMessageUtil.NOT_FOUND); } // Mise à jour de la quantité en stock pour chaque article foreach (CommandeFournisseurLigneEntity l in item.CommandeFournisseurLignes) { StockEntity s = await _service_stock.GetOneById(l.ArticleId); s.Quantite = s.Quantite + l.Quantite; await _service_stock.Update(s); } return(item); }
public async Task <CommandeFournisseurEntity> FournisseurChange(CommandeFournisseurEntity commande_fournisseur, int id_fournisseur) { if (!_repository.Exist(commande_fournisseur.Id)) { throw new NotFoundException(ExceptionMessageUtil.NOT_FOUND); } // Suppression des lignes de la commande // foreach (CommandeFournisseurLigneEntity l in commande_fournisseur.CommandeFournisseurLignes) // { // await _service_ligne.DeleteById(l.Id); // } commande_fournisseur.CommandeFournisseurLignes = null; await Update(commande_fournisseur); // Modification du fournisseur commande_fournisseur.FournisseurId = id_fournisseur; return(await _repository.UpdateAsync(commande_fournisseur)); }
public async Task <CommandeFournisseurLigneEntity> AddArticle(CommandeFournisseurEntity commande_fournisseur, ArticleEntity article, int article_quantite) { foreach (CommandeFournisseurLigneEntity l in commande_fournisseur.CommandeFournisseurLignes) { if (l.ArticleId == article.Id) { l.Quantite = l.Quantite + article_quantite; return(await Update(l)); } } CommandeFournisseurLigneEntity ligne = new CommandeFournisseurLigneEntity(); ligne.CommandeFournisseurId = commande_fournisseur.Id; ligne.ArticleId = article.Id; ligne.Quantite = article_quantite; return(await _repository.AddAsync(ligne)); }
public async Task <CommandeFournisseurEntity> Add(CommandeFournisseurEntity item) { return(await _repository.AddAsync(item)); }
// Algorithme de determination de creation et envoi de CommandeFournisseur automatisees public async Task <List <CommandeFournisseurEntity> > getCommandesFournisseurAuto(CommandeEntity commande) { if (commande == null) { throw new NullReferenceException(nameof(commande)); } // liste des references de lignes necessitant un restock List <CommandeLigneEntity> lignes_pour_restock = new List <CommandeLigneEntity>(); // liste des references des Fournisseur impliqués List <FournisseurEntity> liste_fournisseurs = new List <FournisseurEntity>(); // liste finale des CommandeFournisseur automatiques, à enregistrer puis envoyer List <CommandeFournisseurEntity> liste_commandes_auto = new List <CommandeFournisseurEntity>(); foreach (var ligne in commande.CommandeLignes) { var proj = _service_stock_projection.Value.Projection(ligne.ArticleId).Result; Console.WriteLine(proj); // si la projection MOINS la quantite souhaitee met en peril le stock (inferieur au seuil de stock minimal parametre : aka. Article.Threshold) if ((proj - ligne.Quantite) <= ligne.Article.Threshold) { // on reference la ligne en question lignes_pour_restock.Add(ligne); // on reference le Fournisseur isolement, en verifiant qu'il ne soit pas deja reference FournisseurEntity fournisseur = await _service_fournisseur.GetOneById(ligne.Article.FournisseurId); if (!liste_fournisseurs.Contains(fournisseur)) { liste_fournisseurs.Add(fournisseur); } } } // si effectivement des lignes de la Commande Client ont ete referencees... if (lignes_pour_restock.Count > 0) { // ... on parcours chaque Fournisseur pour lui attribuer une CommandeFournisseur foreach (var fournisseur in liste_fournisseurs) { var commande_auto = new CommandeFournisseurEntity(); commande_auto.isAuto = true; commande_auto.CommandeFournisseurLignes = new List <CommandeFournisseurLigneEntity>(); commande_auto.FournisseurId = fournisseur.Id; // on lui associe le bon fournisseur, notamment pour l'adresse ; et en general car l'information semble pertinente // on isole les lignes de commande pour ce Fournisseur uniquement, grace a List<T>.FindAll(...conditions...) List <CommandeLigneEntity> lignes_a_traiter = lignes_pour_restock.FindAll(o => o.Article.FournisseurId == fournisseur.Id); foreach (var ligne in lignes_a_traiter) { CommandeFournisseurLigneEntity new_ligne = new CommandeFournisseurLigneEntity(); new_ligne.ArticleId = ligne.Article.Id; new_ligne.Quantite = ligne.Article.Threshold * 2; // 2 x le seuil // anicennement :: calculateArticleAdvisedQuantity(ligne.Article, projectionPourCalcul); commande_auto.CommandeFournisseurLignes.Add(new_ligne); // enregistrement liste_commandes_auto.Add(commande_auto); } } } return(liste_commandes_auto); }