/// <summary> /// Validation du panier /// </summary> /// <param name="contract">numéro de contrat</param> /// <returns></returns> public ActionResult SaveAll(string contract) { //recuperation du user actif string user = System.Web.HttpContext.Current.User.Identity.Name.ToString(); //generation de numéro de demande DateTime datee = DateTime.Now; sr_ref = (System.Web.HttpContext.Current.User.Identity.Name.ToString().Remove(0, 5)) + "-" + datee.ToString("yyyy-MM-dd") + "-" + datee.ToString("HH:mm"); sr_ref = sr_ref.Replace(':', '-'); fileName = sr_ref; try { //recuperation de l'id user int fK_ID_actors = (db.tbl_607_actors.Where(u => u.id_uid == user)).First().id; //recuperation de l'id contrat int contractID = db.tbl_607_order.Where(t => t.order_number == contract).Select(t => t.ID).First(); //sauvegarde de shipping request tbl_607_shipping_request tbl_607_Shipping_Request = new tbl_607_shipping_request(); tbl_607_Shipping_Request.request_date = DateTime.Now; tbl_607_Shipping_Request.FK_ID_actors = fK_ID_actors; tbl_607_Shipping_Request.FK_order = contractID; tbl_607_Shipping_Request.shipping_request_ref = sr_ref; db.tbl_607_shipping_request.Add(tbl_607_Shipping_Request); db.SaveChanges(); //sauvegarde //recuperation de l'id de shipping request int idShippingRequest = db.tbl_607_shipping_request.Where(t => t.shipping_request_ref == sr_ref).Select(t => t.ID).First(); //sauvegarde de shipping request details tbl_607_shipping_request_details tbl_607_Shipping_Request_Details = new tbl_607_shipping_request_details(); foreach (KeyValuePair <int, int> value in partialSave) { tbl_607_Shipping_Request_Details.FK_ID_order_details = value.Key; tbl_607_Shipping_Request_Details.shipping_quantity = value.Value; tbl_607_Shipping_Request_Details.reception_quantity = 0; tbl_607_Shipping_Request_Details.FK_shipping_request = idShippingRequest; db.tbl_607_shipping_request_details.Add(tbl_607_Shipping_Request_Details); db.SaveChanges(); //sauvegarde } return(Content(sr_ref)); } catch (Exception ex) { //generation de la vue affichage erreur return(RedirectToAction("Index", "Ooops", new { message = ex })); } }
public ActionResult SaveData() { try { // vérification de l'existance du BL // extraction des numeros de BL existants sur le contrat var BLBase = (db.tbl_607_shipping_delivery.Include(t => t.tbl_607_shipping_request).Include(s => s.tbl_607_shipping_request.tbl_607_order) .Include(o => o.tbl_607_shipping_request.tbl_607_order.tbl_607_order_details)) .Where(o => o.tbl_607_shipping_request.tbl_607_order.ID == BottlereceptionWizardViewModelTemp.idcontract).Select(t => t.BL_ref).ToList(); tbl_607_shipping_delivery tbl_607_Shipping_Delivery = new tbl_607_shipping_delivery(); // comparaison avec le numero saisi par l'utilisateur var Control = BLBase.Contains(BottlereceptionWizardViewModelTemp.BL_ref); if (Control) { //BL existant, nous allons donc uniquement proceder à un update } else { //BL inexistant, creation tbl_607_Shipping_Delivery.BL_ref = BottlereceptionWizardViewModelTemp.BL_ref; tbl_607_Shipping_Delivery.reception_date = BottlereceptionWizardViewModelTemp.reception_date; tbl_607_Shipping_Delivery.FK_ID_shipping_request = BottlereceptionWizardViewModelTemp.FK_ID_shipping_request; db.tbl_607_shipping_delivery.Add(tbl_607_Shipping_Delivery); db.SaveChanges(); //sauvegarde } // le certificat de conformite est unique et est lie a une bouteille tbl_607_conformity_certificate tbl_607_Conformity_Certificate = new tbl_607_conformity_certificate(); tbl_607_Conformity_Certificate.ID = BottlereceptionWizardViewModelTemp.conformity_certificate; tbl_607_Conformity_Certificate.fabrication_date = BottlereceptionWizardViewModelTemp.fabrication_date; tbl_607_Conformity_Certificate.expiration_date = BottlereceptionWizardViewModelTemp.expiration_date; db.tbl_607_conformity_certificate.Add(tbl_607_Conformity_Certificate); db.SaveChanges(); //sauvegarde // recuperation des id des enregistrements crees var FK_ID_shipping_delivery = db.tbl_607_shipping_delivery.Select(t => t.ID).Max(); // recuperation de l'id location pour stock var stock = db.tbl_607_location.Where(t => t.bottle_location == "STOCK").Select(t => t.ID).First(); // enregistrement dans la table bouteille tbl_607_bottle tbl_607_Bottle = new tbl_607_bottle(); tbl_607_Bottle.manufacturer_bottle_number = BottlereceptionWizardViewModelTemp.manufacturer_bottle_number; tbl_607_Bottle.bottle_conti_number = BottlereceptionWizardViewModelTemp.bottle_conti_number; tbl_607_Bottle.FK_ID_conformity_certificate = BottlereceptionWizardViewModelTemp.conformity_certificate; tbl_607_Bottle.FK_ID_shipping_delivery = FK_ID_shipping_delivery; tbl_607_Bottle.FK_ID_order = BottlereceptionWizardViewModelTemp.idcontract; tbl_607_Bottle.FK_ID_location = stock; db.tbl_607_bottle.Add(tbl_607_Bottle); db.SaveChanges(); //sauvegarde // mise à jour de la quantité recue sur le poste tbl_607_order_details tbl_607_Order_Detail = db.tbl_607_order_details.Where(t => t.poste_number == BottlereceptionWizardViewModelTemp.posteNumber && t.FK_ID_order == BottlereceptionWizardViewModelTemp.idcontract).First(); tbl_607_Order_Detail.recieved_quantity = tbl_607_Order_Detail.recieved_quantity++; db.SaveChanges(); //sauvegarde // mise a jour de la quantité sur la demande de livraison tbl_607_shipping_request_details tbl_607_Shipping_Request_Details = db.tbl_607_shipping_request_details.Where(t => t.FK_shipping_request == BottlereceptionWizardViewModelTemp.FK_ID_shipping_request).FirstOrDefault(); tbl_607_Shipping_Request_Details.reception_quantity = tbl_607_Shipping_Request_Details.reception_quantity++; db.SaveChanges(); //sauvegarde // Recuperation de l'ID Bottle. L'ID gaz est deja connu = key du dico var idBottle = db.tbl_607_bottle.Select(t => t.ID).Max(); //Nouvelle relève: valeurs par défaut 999bars et acteur: admin tbl_607_gaz_reporting tbl_607_Gaz_Reporting = new tbl_607_gaz_reporting(); tbl_607_Gaz_Reporting.pressure_value = 999; tbl_607_Gaz_Reporting.FK_ID_actors = 29; tbl_607_Gaz_Reporting.FK_ID_bottle = idBottle; tbl_607_Gaz_Reporting.reporting_date = DateTime.Now; db.tbl_607_gaz_reporting.Add(tbl_607_Gaz_Reporting); // Recuperation des reals gaz dans le dictionnaire foreach (KeyValuePair <int, float> value in Tbl_607_Real_Gaz_Content_temp) { tbl_607_real_gaz_content tbl_607_Real_Gaz_Content = new tbl_607_real_gaz_content(); tbl_607_join_bottle_gaz tbl_607_Join_Bottle_Gaz = new tbl_607_join_bottle_gaz(); // Enregistrement des reals gaz tbl_607_Real_Gaz_Content.real_content = value.Value; //force l'ecriture dans la base alors que nous sommes encore dans la boucle db.tbl_607_real_gaz_content.Add(tbl_607_Real_Gaz_Content); db.SaveChanges(); //sauvegarde //// Recuperation de l'id real gaz var fk_real = db.tbl_607_real_gaz_content.Select(t => t.ID).Max(); //Ecriture de la jointure tbl_607_Join_Bottle_Gaz.FK_ID_gaz = value.Key; tbl_607_Join_Bottle_Gaz.FK_ID_bottle = idBottle; tbl_607_Join_Bottle_Gaz.FK_ID_real_content = fk_real; db.tbl_607_join_bottle_gaz.Add(tbl_607_Join_Bottle_Gaz); //force l'ecriture dans la base alors que nous sommes encore dans la boucle db.SaveChanges(); //sauvegarde } //generation de la vue return(View("Index")); } catch (Exception ex) { //generation de la vue affichage erreur return(RedirectToAction("Index", "Ooops", new { message = ex })); } }