// map a Request for Proposal from a Linq to Xml XElement
        public RequestForProposal MapFrom(XElement elem)
        {
            RequestForProposal rfp = new RequestForProposal();

            rfp.ID = new Guid(elem.Attribute("id").Value);
            rfp.Status = elem.Attribute("status").Value;
            rfp.Title = elem.Element("title").Value;
            rfp.Description = elem.Element("description").Value;
            rfp.CreationDate = DateTime.Parse(elem.Element("creationDate").Value, new CultureInfo("EN-us"));

            if (elem.Element("completionDate") != null)
                rfp.CompletionDate = DateTime.Parse(elem.Element("completionDate").Value, new CultureInfo("EN-us"));

            // invited vendors
            foreach (XElement vendorElem in elem.Element("invitedVendors").Elements("vendor"))
            {
                Vendor vendor = Vendors.Retrieve(Convert.ToInt32(vendorElem.Attribute("id").Value, new CultureInfo("EN-us")));
                rfp.InvitedVendors.Add(vendor);
            }

            // map received proposals in the list
            foreach (var proposal in elem.Element("vendorProposals").Elements("vendorProposal"))
            {
                Vendor vendor = Vendors.Retrieve(int.Parse(proposal.Attribute("vendorId").Value, new CultureInfo("EN-us")));
                VendorProposal vendorProposal = new VendorProposal(vendor.Id);
                vendorProposal.Value = double.Parse(proposal.Attribute("value").Value, new CultureInfo("EN-us"));
                vendorProposal.Date = DateTime.Parse(proposal.Attribute("date").Value, new CultureInfo("EN-us"));
                rfp.VendorProposals.Add(vendor.Id, vendorProposal);
            }

            // map best proposal
            if (elem.Element("bestProposal") != null)
            {
                Vendor bestVendor = Vendors.Retrieve(Convert.ToInt32(elem.Element("bestProposal").Attribute("vendorId").Value, new CultureInfo("EN-us")));
                rfp.BestProposal = new VendorProposal(bestVendor.Id);
                rfp.BestProposal.Value = double.Parse(elem.Element("bestProposal").Attribute("value").Value, new CultureInfo("EN-us"));
                rfp.BestProposal.Date = DateTime.Parse(elem.Element("bestProposal").Attribute("date").Value, new CultureInfo("EN-us"));
            }

            return rfp;
        }
        public ActionResult CreateRfp(RequestForProposal rfp)
        {
            IPurchasingService purchasingService = new PurchasingServiceClient();
            rfp.Status = "active";
            string[] invitedVendors = Request.Form["InvitedVendors"].Split(',');
            foreach (var invitedVendor in invitedVendors)
            {
                rfp.InvitedVendors.Add(VendorRepository.Retrieve(int.Parse(invitedVendor)));
            }

            try
            {
                SubmitPurchasingProposalResponse response = purchasingService.SubmitPurchasingProposal(new SubmitPurchasingProposalRequest(rfp));
            }
            catch (Exception)
            {

                throw;
            }

            return RedirectToAction("Index");
        }