public ActionResult UpdateAjaxInvoice(string name, string pk, string value)
        {
            Invoice invoice = GetInvoice(int.Parse(pk));

            if (invoice == null)
            {
                return(RedirectToAction("Index"));
            }

            InvoiceDataUpdtAjaxPoco retour = invoiceProvider.UpdateField(invoice, name, value);

            return(Json(retour, JsonRequestBehavior.AllowGet));
        }
示例#2
0
        /// <summary>
        /// Update selon le nom sur différent objets
        /// </summary>
        public FORM.InvoiceDataUpdtAjaxPoco UpdateField(Invoice invoicepo, string Name, string Value, bool saveInBase = true)
        {
            FORM.InvoiceDataUpdtAjaxPoco retour = new InvoiceDataUpdtAjaxPoco();
            if (invoicepo.IDInvoice < 0)
            {
                saveInBase = false;                          // impossible de copier en base
            }
            List <string> nameAlloweds = new List <string>(new string[] { "Invoice", "RefInvoice", "DateInvoice", "BuyerAddress",
                                                                          "Adress1", "Adress2", "Adress3", "Postcode", "City", "Country", "postCode", "ContactMail", "ContactPhone", "Identity", "Compagny",
                                                                          "RefBuyer", "RefSeller", "SellerAddress", "Lines", "LineQuantity", "LineAmount", "LineLabel" });

            if (Name.Split('_').Count() < 2)
            {
                throw new Exception("Paramètres non autorisés");
            }
            string NameObject = Name.Split('_')[Name.Split('_').Count() - 2].Split('|')[0];
            string IdObject   = Name.Split('_')[Name.Split('_').Count() - 2].Split('|').Count() > 1 ? Name.Split('_')[Name.Split('_').Count() - 2].Split('|')[1] : "";
            string NameField  = Name.Split('_')[Name.Split('_').Count() - 1];


            if (!nameAlloweds.Contains(NameObject) || !nameAlloweds.Contains(NameField))
            {
                throw new Exception("Paramètres non autorisés");
            }
            switch (NameObject)
            {
            // Modification de la facture
            case "Invoice":
                invoicepo[NameField] = Value;
                if (saveInBase)
                {
                    this.UpdateBubble(invoicepo, NameField, Value);
                }
                break;

            // modification des ligne de la facture
            case "Lines":
                InvoiceLine line = invoicepo.Lines.FirstOrDefault(l => l.IDLine == int.Parse(IdObject));
                line[NameField] = Value;
                if (saveInBase)
                {
                    this.UpdateBubble(line, NameField, Value);
                }
                break;

            // Contact Acheteur
            case "BuyerAddress":
                if (invoicepo.BuyerAddress == null)
                {
                    invoicepo.BuyerAddress = new Address();
                }
                invoicepo.BuyerAddress[NameField] = Value;
                if (saveInBase)
                {
                    SOLUTIONS.INVOICES.CONTACT.AddressProvider addressProvide = new AddressProvider(this.Connector);
                    addressProvide.SaveAddress(invoicepo.BuyerAddress);
                    if (invoicepo.BuyerIDAddress != invoicepo.BuyerAddress.IDAddress)
                    {
                        this.UpdateBubble(invoicepo, "BuyerIDAddress", invoicepo.BuyerAddress.IDAddress);
                    }
                }
                break;

            // Contact Vendeur
            case "SellerAddress":
                if (invoicepo.SellerAddress == null)
                {
                    invoicepo.SellerAddress = new Address();
                }
                invoicepo.SellerAddress[NameField] = Value;
                if (saveInBase)
                {
                    SOLUTIONS.INVOICES.CONTACT.AddressProvider addressProvide = new AddressProvider(this.Connector);
                    addressProvide.SaveAddress(invoicepo.SellerAddress);
                    if (invoicepo.SellerIDAddress != invoicepo.SellerAddress.IDAddress)
                    {
                        this.UpdateBubble(invoicepo, "SellerIDAddress", invoicepo.SellerAddress.IDAddress);
                    }
                }
                break;

            //NA
            default:
                break;
            }

            // retour des données sur la factur (calcul montant)
            // !!! normalement ne devrai pas etre ici faire une méthode spécial dans le controlleur, qui retourne un JSON qui permet de mettre a jour la facture
            if (NameObject == "Lines")
            {
                InvoiceLine line  = invoicepo.Lines.FirstOrDefault(l => l.IDLine == int.Parse(IdObject));
                double      somme = invoicepo.Lines.Sum(ln => ln.LineQuantity * ln.LineAmount);
                invoicepo.FinalAmount = somme;
                if (saveInBase)
                {
                    this.UpdateBubble(invoicepo, "FinalAmount", somme);
                }
                retour.LastUpdtline = new InvoiceDataUpdtAjaxPoco.LineUpdtAjaxPoco();
                retour.LastUpdtline.FromPo(line);
                //return "€ " + (line.LineQuantity * line.LineAmount).ToString() + "|€ " + somme;
            }
            retour.FromPo(invoicepo);
            return(retour);
        }