public async Task <CommandeEntity> AddAsync(CommandeEntity item) { _context.CommandeEntities.Add(item); await _context.SaveChangesAsync(); return(item); }
public async Task <CommandeEntity> UpdateAsync(CommandeEntity item) { _context.Update(item); await _context.SaveChangesAsync(); return(item); }
// ARTICLES public async Task <CommandeLigneEntity> AddArticle(CommandeEntity commande, int id_article) { /* * delegation service CommandeLigne */ return(await _service_ligne.AddArticle(commande, id_article)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Numero,Commentaire,ContactId,NomCommandeStatutId,IsDeleted,CreatedAt")] CommandeEntity commandeEntity) { if (id != commandeEntity.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(commandeEntity); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CommandeEntityExists(commandeEntity.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["ContactId"] = new SelectList(_context.ContactEntities, "Id", "Id", commandeEntity.ContactId); ViewData["NomCommandeStatutId"] = new SelectList(_context.NomCommandeStatutEntities, "Id", "Code", commandeEntity.NomCommandeStatutId); return(View(commandeEntity)); }
public async Task <CommandeEntity> ValidateAsync(CommandeEntity item) { item.NomCommandeStatutId = _context.NomCommandeStatutEntities.Where(o => o.Code == "A").FirstOrDefault().Id; // A = en attente de preparation _context.Update(item); await _context.SaveChangesAsync(); return(item); }
public async Task <CommandeEntity> DeleteAsync(CommandeEntity item) { item.IsDeleted = true; _context.Update(item); await _context.SaveChangesAsync(); return(item); }
public async Task <CommandeEntity> Update(CommandeEntity item) { if (!_repository.Exist(item.Id)) { throw new NotFoundException(ExceptionMessageUtil.NOT_FOUND); } return(await _repository.UpdateAsync(item)); }
public async Task <CommandeLigneEntity> AddArticle(CommandeEntity commande, int id_article) { CommandeLigneEntity ligne = new CommandeLigneEntity(); ligne.Commande = commande; ligne.Article = await _service_article.GetOneById(id_article); return(await _repository.AddAsync(ligne)); }
public async Task <bool> IsReadyForShipment(CommandeEntity commande) { foreach (CommandeLigneEntity ligne in commande.CommandeLignes) { if (ligne.Quantite > ligne.Article.Stock.Quantite) { return(await Task.FromResult(false)); } } return(await Task.FromResult(true)); }
public async Task <IActionResult> Create([Bind("Id,Numero,Commentaire,ContactId,NomCommandeStatutId,IsDeleted")] CommandeEntity commandeEntity) { if (ModelState.IsValid) { _context.Add(commandeEntity); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["ContactId"] = new SelectList(_context.ContactEntities, "Id", "Id", commandeEntity.ContactId); ViewData["NomCommandeStatutId"] = new SelectList(_context.NomCommandeStatutEntities, "Id", "Code", commandeEntity.NomCommandeStatutId); return(View(commandeEntity)); }
// LIVRAISON :: OK public async Task <IActionResult> StatutConfirmLivraison(int id) { CommandeEntity commande = await _service_commande.GetOneById(id); if (commande != null) { commande.NomCommandeStatut = await _context.NomCommandeStatutEntities.Where(o => o.Code == "V").FirstOrDefaultAsync(); await _service_commande.Update(commande); } return(RedirectToAction(nameof(Dashboard), new { filtre = "V" })); }
public async Task <CommandeEntity> UploadStock(CommandeEntity item) { // impacte le stock if (!_repository.Exist(item.Id)) { throw new NotFoundException(ExceptionMessageUtil.NOT_FOUND); } // Mise à jour de la quantité en stock pour chaque article foreach (CommandeLigneEntity l in item.CommandeLignes) { StockEntity s = await _service_stock.GetOneById(l.ArticleId); s.Quantite = s.Quantite + l.Quantite; await _service_stock.Update(s); } return(item); }
public async Task <CommandeEntity> GetPanierByContactId(int id) { var _panier = await _context.CommandeEntities .Where(o => o.NomCommandeStatut.Code == "P" && o.ContactId == id) .FirstOrDefaultAsync(); if (_panier is null || _panier.Id == 0) { CommandeEntity _commande = new CommandeEntity(); _commande.ContactId = id; _commande.NomCommandeStatutId = _context.NomCommandeStatutEntities.Where(o => o.Code == "P").FirstOrDefault().Id; // hardCode "PANIER" await AddAsync(_commande); return(await GetOneByIdAsync(_commande.Id)); } return(await GetOneByIdAsync(_panier.Id)); }
// ANNULATION public async Task <IActionResult> StatutAnnulation(int id) { CommandeEntity commande = await _service_commande.GetOneById(id); bool wasLivraison = false; if (commande != null) { wasLivraison = commande.NomCommandeStatut.Code == "L"; commande.NomCommandeStatut = await _context.NomCommandeStatutEntities.Where(o => o.Code == "X").FirstOrDefaultAsync(); await _service_commande.Update(commande); // si c'etait en cours de livraison, alors on renfloue le stock if (wasLivraison) { await _service_commande.UploadStock(commande); } } return(RedirectToAction(nameof(Dashboard), new { filtre = "X" })); }
// 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); }
public async Task <CommandeEntity> Add(CommandeEntity item) { return(await _repository.AddAsync(item)); }