Ejemplo n.º 1
0
        public async Task <IHttpActionResult> Putcommande(int id, commande commande)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != commande.id)
            {
                return(BadRequest());
            }

            db.Entry(commande).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!commandeExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public void UpdateStock(commande cmd)
        {
            GestionStock gs             = new GestionStock();
            stock        st             = gs.FindById(cmd.Stock.GetValueOrDefault());
            var          httpWebRequest = (HttpWebRequest)WebRequest.Create("http://localhost:18080/refugeesCamp-web/api/stock");

            httpWebRequest.ContentType = "application/json";
            httpWebRequest.Method      = "POST";

            using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
            {
                string json = "	{\"stockType\": \"" + st.stockType + "\",\"qteTotal\": " + cmd.qteOfProduct + ",\"qteInStock\": " + cmd.qteOfProduct + ",\"stockValue\": " + cmd.totalPrice + "}";

                streamWriter.Write(json);
                streamWriter.Flush();
                streamWriter.Close();
            }

            var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();

            using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
            {
                var result = streamReader.ReadToEnd();
            }
        }
Ejemplo n.º 3
0
        public static void Inserer(commande c, List <LigneCommande> lc)
        {
            Connexion.Ouvrir();
            SqlTransaction transaction = Connexion.cn.BeginTransaction();
            SqlCommand     cmdaj       = new SqlCommand();

            cmdaj.Connection  = Connexion.cn;
            cmdaj.Transaction = transaction;
            try {
                //commande1
                cmdaj.CommandText = "insert into commande(Num_cmd, cin_cl, date_cmd) Values('" + c.Num_cmd + "','" + c.cin_cl + "','" + c.date_cmd + "')";
                cmdaj.ExecuteNonQuery();
                //commande2
                for (int i = 0; i < lc.Count(); i++)
                {
                    cmdaj.CommandText = "insert into LigneCommande(num_cmd, Ref_Prod, qte) Values('" + lc[i].num_cmd + "','" + lc[i].Ref_Prod + "','" + lc[i].qte + "')";
                    cmdaj.ExecuteNonQuery();
                }
                transaction.Commit();
            }catch (Exception ex)
            {
                Console.Write(ex);
                transaction.Rollback();
            }
            finally
            {
                Connexion.Close();
            }
        }
Ejemplo n.º 4
0
        public ActionResult DeleteConfirmed(int id)
        {
            commande commande = db.commandes.Find(id);

            db.commandes.Remove(commande);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 5
0
        public async Task <IHttpActionResult> Getcommande(int id)
        {
            commande commande = await db.commande.FindAsync(id);

            if (commande == null)
            {
                return(NotFound());
            }

            return(Ok(commande));
        }
Ejemplo n.º 6
0
        public async Task <IHttpActionResult> Postcommande(commande commande)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.commande.Add(commande);
            await db.SaveChangesAsync();

            return(CreatedAtRoute("DefaultApi", new { id = commande.id }, commande));
        }
Ejemplo n.º 7
0
 private void Nouveau_Cde_Click(object sender, EventArgs e)
 {
     if (string.IsNullOrEmpty(Txt_NumCde.Text) || string.IsNullOrEmpty(Txt_cin.Text))
     {
         MessageBox.Show("please fill the empty Box");
     }
     else
     {
         commande c = new commande(Convert.ToInt32(Txt_NumCde.Text), Convert.ToInt32(Txt_cin.Text), Date_Cde.Value.Date);
         CommandeDAO.Inserer(c, list_commande);
         list_commande.Clear();
     }
 }
Ejemplo n.º 8
0
 //Initialise une commande et retourne un numero de commande
 public int MAddCommande()
 {
     var commandeItem = new commande
     {
         prixtotal = 0,
         datecommande = DateTime.Now,
         etatcommande = "brouillon"
     };
     db.commande.Add(commandeItem);
     db.SaveChanges();
     var CommandeIDItem = (from c in db.commande select c).OrderByDescending(c => c.datecommande).FirstOrDefault();
     return CommandeIDItem.commandeID;
 }
Ejemplo n.º 9
0
        public ActionResult ChangeStatusToShipped(int id)
        {
            commande cmd = gCommandes.FindById(id);

            cmd.status  = 1;
            cmd.shipped = DateTime.Now;
            StockConsumeController stCtrl = new StockConsumeController();

            stCtrl.UpdateStock(cmd);//call method post of rest api to update stock
            gCommandes.Update(cmd);
            gCommandes.Commit();
            return(RedirectToAction("List"));
        }
Ejemplo n.º 10
0
 public ActionResult Edit([Bind(Include = "id_commande,date_rdv,id_user,id_status,id_mode_paiement")] commande commande)
 {
     if (ModelState.IsValid)
     {
         db.Entry(commande).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.id_user          = new SelectList(db.users, "id_user", "login", commande.id_user);
     ViewBag.id_status        = new SelectList(db.status, "id_status", "nom", commande.id_status);
     ViewBag.id_mode_paiement = new SelectList(db.mode_paiement, "id_mode_paiement", "nom", commande.id_mode_paiement);
     return(View(commande));
 }
Ejemplo n.º 11
0
        public async Task <IHttpActionResult> Deletecommande(int id)
        {
            commande commande = await db.commande.FindAsync(id);

            if (commande == null)
            {
                return(NotFound());
            }

            db.commande.Remove(commande);
            await db.SaveChangesAsync();

            return(Ok(commande));
        }
Ejemplo n.º 12
0
        // GET: commandes/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            commande commande = db.commandes.Find(id);

            if (commande == null)
            {
                return(HttpNotFound());
            }
            return(View(commande));
        }
Ejemplo n.º 13
0
        // GET: commandes/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            commande commande = db.commandes.Find(id);

            if (commande == null)
            {
                return(HttpNotFound());
            }
            ViewBag.id_user          = new SelectList(db.users, "id_user", "login", commande.id_user);
            ViewBag.id_status        = new SelectList(db.status, "id_status", "nom", commande.id_status);
            ViewBag.id_mode_paiement = new SelectList(db.mode_paiement, "id_mode_paiement", "nom", commande.id_mode_paiement);
            return(View(commande));
        }
Ejemplo n.º 14
0
        public ActionResult Update(int id, FormCollection collection)
        {
            if (ModelState.IsValid)
            {
                commande prov = gCommandes.FindById(id);
                prov.address      = collection["address"];
                prov.country      = collection["country"];
                prov.qteOfProduct = int.Parse(collection["qteOfProduct"]);

                gCommandes.Update(prov);
                gCommandes.Commit();
                return(RedirectToAction("List"));
            }
            else
            {
                return(View());
            }
        }
Ejemplo n.º 15
0
        public ActionResult AddToPanier(produit Produit)
        {
            // GET Session info
            string cart = GetCartId(this.HttpContext);

            string URLReq = HttpContext.Request.RawUrl;

            // CHECK si l'utilisateur existe
            var cartItem = db.client.SingleOrDefault(c => c.clientID == cart);
            var commandedetailtmpItem = new detailcommandetmp();
            var commandedetailItem    = new detailcommande();

            if (cartItem == null)
            {
                commandedetailtmpItem.sessionID          = cart;
                commandedetailtmpItem.datedetailcommande = DateTime.Now;
                commandedetailtmpItem.quantitee          = 1;
                commandedetailtmpItem.restaurantID       = 1;
                commandedetailtmpItem.commandeID         = 1;
                db.detailcommandetmp.Add(commandedetailtmpItem);
            }
            else
            {
                commandedetailItem.clientID           = cart;
                commandedetailItem.datedetailcommande = DateTime.Now;
                commandedetailItem.quantitee          = 1;
                commandedetailItem.restaurantID       = 1;
                commandedetailItem.commandeID         = 1;
                db.detailcommandetmp.Add(commandedetailtmpItem);
            }

            var commandeItem = new commande();

            commandeItem.prixtotal    = 30;
            commandeItem.datecommande = DateTime.Now;
            commandeItem.etatcommande = "brouillon";
            db.commande.Add(commandeItem);

            db.SaveChanges();

            var listedetailcommande = (from dc in db.detailcommandetmp where dc.sessionID == cart select dc).ToList();

            return(View("Commande", listedetailcommande));
        }
Ejemplo n.º 16
0
 private void btnAjouter_Click(object sender, EventArgs e)
 {
     if (String.IsNullOrEmpty(textNumero.Text))
     {
         MessageBox.Show("le numéro est obligatoires", "Message Erreur", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     else
     {
         commande commande = new commande()
         {
             numero = int.Parse(textNumero.Text.Trim()),
             date   = int.Parse(textDate.Text.Trim()),
         };
         if (metier.CreerCommande(commande))
         {
             MessageBox.Show("Commande créer avec succès", "Message Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
             textNumero.Clear();
             textDate.Clear();
         }
     }
 }
Ejemplo n.º 17
0
        public ActionResult Create(CommandeViewModel cmdVM, string type)
        {
            user     currentUser = SessionPersister.User;
            var      StockCtrl   = new GestionStock();
            commande cmd         = new commande();

            cmd.address      = cmdVM.Commande.address;
            cmd.country      = cmdVM.Commande.country;
            cmd.qteOfProduct = cmdVM.Commande.qteOfProduct;
            cmd.totalPrice   = 0;
            cmd.status       = 0;
            cmd.ordered      = DateTime.Now;//.ToString("yyyy-MM-dd HH:mm:ss");
            cmd.Admin        = currentUser.id;
            cmd.Provider     = cmdVM.PostedProviderId;
            cmd.Stock        = 1;

            /*//stock currentStock =  StockCtrl.FindByCondition(p=>p.stockType.Equals(type)).First();
             * commande cmd = new commande();//cmdVM.Commande;
             * provider prv = new provider();
             * GestionProvider gProvider = new GestionProvider();
             * prv = gProvider.FindById(cmdVM.PostedProviderId);
             * cmd.Admin1= (Admin)currentUser;
             * //cmd.Admin1 =(Admin) currentUser;
             * //cmd.stock1 = currentStock;
             * //cmd.provider1 = prv;
             *
             * cmd.totalPrice=0;
             * cmd.status=0;*/
            if (ModelState.IsValid)
            {
                gCommandes.Create(cmd);
                gCommandes.Commit();
                return(RedirectToAction("Index"));
            }
            else
            {
                return(View(cmd));
            }
        }
Ejemplo n.º 18
0
        public List <OrdersViewModel> getOrdersViewModel()
        {
            var list = ordersList.Select(s => new { s.id, s.address, s.country, s.ordered, s.qteOfProduct, s.shipped, s.status, s.totalPrice, s.Admin, s.Stock, s.Provider }).ToList();

            List <OrdersViewModel> orders = new List <OrdersViewModel>();
            int pending = 0;
            int recived = 0;

            foreach (var s in list)
            {
                //Console.WriteLine(s.Admin1.firstName);
                GestionUser     gu = new GestionUser();
                GestionStock    gs = new GestionStock();
                GestionProvider gp = new GestionProvider();

                commande cm = new commande {
                    id = s.id, Admin = s.Admin, Stock = s.Stock, Provider = s.Provider, address = s.address, country = s.country, ordered = s.ordered, qteOfProduct = s.qteOfProduct, shipped = s.shipped, status = s.status, totalPrice = s.totalPrice
                };
                if (cm.status == 0)
                {
                    pending++;
                }
                else
                {
                    recived++;
                }
                user     a  = gu.FindById(cm.Admin.GetValueOrDefault());
                stock    st = gs.FindById(cm.Stock.GetValueOrDefault());
                provider p  = gp.FindById(cm.Provider.GetValueOrDefault());

                orders.Add(new OrdersViewModel {
                    Cmd = cm, AdminName = a.FullName, ProviderName = p.nom, StockType = st.stockType
                });
            }
            OrdersViewModel.pending = pending;
            OrdersViewModel.recived = recived;
            return(orders);
        }
Ejemplo n.º 19
0
        public ActionResult Update(int id)
        {
            commande cmdCurrent = gCommandes.FindById(id);

            return(View(cmdCurrent));
        }
Ejemplo n.º 20
0
 public bool CreerCommande(commande commande)
 {
     ctx.commande.Add(commande);
     return(ctx.SaveChanges() != 0);
 }