private Dictionary<String, Dictionary<String, String>[]> createDictionary4SecondSection(
            string offerRegNumber,
            string participantName,
            string participantUNP,
            string participantAddress,
            string participantMemberRegNumber,
            TAuction auction,
            Contact[] contatcs,
            File[] files)
        {
            Dictionary<String, Dictionary<String, String>[]> dict = new Dictionary<string, Dictionary<string, string>[]>();

            //contacts
            Dictionary<String, String>[] contatcsDict = new Dictionary<string, string>[contatcs == null ? 0 : contatcs.Length];
            for (int i = 0; i < contatcs.Length; i++)
            {
                contatcsDict[i] = new Dictionary<string, string>();
                contatcsDict[i].Add("contactFIO", contatcs[i].FIO);
                contatcsDict[i].Add("contactPhone", contatcs[i].Phones);
                contatcsDict[i].Add("contactFax", contatcs[i].Fax);
                contatcsDict[i].Add("contactEmail", contatcs[i].Email);
                contatcsDict[i].Add("contactOther", contatcs[i].OtherInfo);
            }
            dict.Add("repeatingUnitContact", contatcsDict);

            //files
            Dictionary<String, String>[] filesDict = new Dictionary<string, string>[files == null ? 0 : files.Length];
            for (int i = 0; i < filesDict.Length; i++)
            {
                filesDict[i] = new Dictionary<string, string>();
                filesDict[i].Add("docName", files[i].DocName);
            }
            dict.Add("repeatingUnitDoc", filesDict);

            //other
            Dictionary<String, String>[] other = new Dictionary<string, string>[1];
            other[0] = new Dictionary<string, string>();
            other[0].Add("offerNumber", offerRegNumber);
            other[0].Add("siteAddress", auction.AuctionHeader.PurchaseSite);
            other[0].Add("regNumber", auction.AuctionHeader.AuctionRegNumber);
            other[0].Add("shortName", auction.AuctionHeader.PurchaseName);
            other[0].Add("UNP", participantUNP);
            other[0].Add("fullName", participantName);
            other[0].Add("address", participantAddress);
            other[0].Add("regNumberCustomer", participantMemberRegNumber);
            dict.Add("other", other);

            return dict;
        }
        public ActionResult GenerateRTFOffer4SecondSection(
            string offerRegNumber,
            string participantName,
            string participantUNP,
            string participantAddress,
            string participantMemberRegNumber,
            TAuction auction,
            Contact[] contatcs,
            File[] files)
        {
            Dictionary<String, Dictionary<String, String>[]> dict = createDictionary4SecondSection(
                offerRegNumber,
                participantName,
                participantUNP,
                participantAddress,
                participantMemberRegNumber,
                auction,
                contatcs,
                files);
            string text = TemplatesUtils.generateDocument(Server.MapPath("~") + "Content/static/templates/Offer Prt 2_19032012.rtf", dict);

            return Json(text);
        }
        public ActionResult AddOffer(TOfferInitialData offerInitialData, TAuction auction, Lot4Offer[] lots,
            SecurityDoc[] securityDocs, String content1, String signature1, File[] files1,
            Contact[] contatcs, String content2, String signature2, File[] files2)
        {
            TOffer offer = new TOffer();

            //fill offer info
            TOfferInfo offerInfo = new TOfferInfo();
            offerInfo.OfferRegNumber = offerInitialData.OfferRegNumber;
            offerInfo.ExpiryOfferDate = auction.AuctionInfo.ExpiryOfferDate;
            offerInfo.SecurityPercent = auction.AuctionInfo.SecurityPercent;
            offerInfo.SubjectName = auction.AuctionInfo.SubjectName;
            offer.OfferInfo = offerInfo;

            offer.AuctionHeader = auction.AuctionHeader;
            offer.AuctionID = auction.AuctionID;
            offer.AuctionStatusText = auction.AuctionStatusText;
            offer.BudgetFunding = offerInitialData.BudgetFunding;
            offer.BudgetFundingText = offerInitialData.BudgetFundingText;
            //offer.ServiceFeeFlag =
            //offer.ServiceFeeText =
            offer.Participant = offerInitialData.Participant;

            //fill lots data
            TOfferLotInfo[] offerLots = new TOfferLotInfo[lots == null ? 0 : lots.Length];
            for (int i = 0; i < offerLots.Length; i++)
            {
                offerLots[i] = new TOfferLotInfo();
                offerLots[i].AddInfo = lots[i].OtherInfo;
                //offerLots[i].AuctionLotStatusText =
                offerLots[i].AgreementConsent = 1;
                offerLots[i].Currency = lots[i].CurrencyCode;
                offerLots[i].CurrencyAbb = lots[i].Currency;
                offerLots[i].DeliveryDate = lots[i].Time;
                offerLots[i].DeliveryPlace = lots[i].Place;
                offerLots[i].Description = lots[i].Description;
                offerLots[i].EdIzm = lots[i].EdIzmCode;
                offerLots[i].EdIzmAbb = lots[i].EdIzm;
                offerLots[i].FundingSource = int.Parse(lots[i].FinanceSourceCode);
                offerLots[i].FundingSourceText = lots[i].FinanceSource;
                offerLots[i].LotID = lots[i].LotID;
                offerLots[i].LotVolume = string.IsNullOrEmpty(lots[i].Value) ? 0 : double.Parse(lots[i].Value.Trim().Replace(" ", ""), System.Globalization.CultureInfo.InvariantCulture);
                offerLots[i].NumLot = lots[i].NumLot;
                TOKRBRec[] okrb = new TOKRBRec[lots[i].OKRB.Length];
                for (int j = 0; j < lots[i].OKRB.Length; j++)
                {
                    TOKRBRec okrbRec = new TOKRBRec();
                    okrbRec.OKRBCode = lots[i].OKRB[j].OKRBCode;
                    okrbRec.OKRBID = int.Parse(lots[i].OKRB[j].OKRBID);
                    okrbRec.OKRBName = lots[i].OKRB[j].OKRBName;
                    okrb[j] = okrbRec;
                }
                offerLots[i].OKRBList = okrb;
                offerLots[i].PrefPercent = string.IsNullOrEmpty(lots[i].Correction) ? 0 : double.Parse(lots[i].Correction.Trim().Replace(" ", ""), System.Globalization.CultureInfo.InvariantCulture);
                offerLots[i].PrefReason = lots[i].FoundingCorrection;
                offerLots[i].SecurityValue = auction.AuctionInfo.SecurityPercent;
                offerLots[i].StartPrice = string.IsNullOrEmpty(lots[i].Price) ? 0 : double.Parse(lots[i].Price.Trim().Replace(" ", ""), System.Globalization.CultureInfo.InvariantCulture);
                offerLots[i].VolumeMethod = lots[i].CalcMethod;
            }
            offer.Lots = offerLots;

            //fill contact data
            TContactPerson[] tContatcs=new TContactPerson[contatcs==null?0:contatcs.Length];
            for (int i = 0; i < contatcs.Length; i++)
            {
                tContatcs[i] = new TContactPerson();
                tContatcs[i].FIO = contatcs[i].FIO;
                tContatcs[i].Phone = contatcs[i].Phones;
                tContatcs[i].Fax = contatcs[i].Fax;
                tContatcs[i].Email = contatcs[i].Email;
                tContatcs[i].AddInfo = contatcs[i].OtherInfo;
            }
            offer.ContactPersons = tContatcs;

            //fill security docs data
            TSecurityDoc[] tSecurityDocs = new TSecurityDoc[securityDocs==null?0:securityDocs.Length];
            for (int i = 0; i < tSecurityDocs.Length; i++)
            {
                tSecurityDocs[i] = new TSecurityDoc();
                //tSecurityDocs[i].ConfirmDate = ...;
                tSecurityDocs[i].Currency = securityDocs[i].CurrencyCode;
                tSecurityDocs[i].CurrencyAbb = securityDocs[i].Currency;
                tSecurityDocs[i].DocDate = DateTimeUtils.DateTimeToDouble(DateTime.Parse(securityDocs[i].DocDate.Trim().Replace(" ", string.Empty)));
                tSecurityDocs[i].DocNum = securityDocs[i].DocNumber;
                tSecurityDocs[i].DocTypeText = securityDocs[i].SecurityView;
                tSecurityDocs[i].ExpiryDate = DateTimeUtils.DateTimeToDouble(DateTime.Parse(securityDocs[i].SecurityPeriod.Trim().Replace(" ", string.Empty)));
                tSecurityDocs[i].SecuritySum = string.IsNullOrEmpty(securityDocs[i].SecurityValue) ? 0 : double.Parse(securityDocs[i].SecurityValue, System.Globalization.CultureInfo.InvariantCulture);
            }
            offer.SecurityDocs = tSecurityDocs;

            GovernmentPurchases.WebReference.TEDContent eContent1 = new GovernmentPurchases.WebReference.TEDContent();
            eContent1.Content = content1;
            eContent1.Signature = signature1;

            GovernmentPurchases.WebReference.TEDContent eContent2 = new GovernmentPurchases.WebReference.TEDContent();
            eContent2.Content = content2;
            eContent2.Signature = signature2;

            TAuthHeader header = new TAuthHeader();
            header.SessionID = (String)Session["sessionID"];
            header.SessionKey = (String)Session["sessionKey"];
            client.TAuthHeaderValue = header;

            int offerID = new int();
            client.AddOffer(offer, eContent1, eContent2, ref offerID);

            //upload files
            GovernmentPurchases.IUploadFiles.IUploadFilesservice fileClient = new GovernmentPurchases.IUploadFiles.IUploadFilesservice();
            //upload I section files
            if (files1 != null)
            {
                GovernmentPurchases.IUploadFiles.TEDocument document = new GovernmentPurchases.IUploadFiles.TEDocument();
                GovernmentPurchases.IUploadFiles.TEDContent cont = new GovernmentPurchases.IUploadFiles.TEDContent();

                for (int i = 0; i < files1.Length; i++)
                {
                    document.IDParent = offerID;
                    document.FileName = files1[i].FileName;
                    document.NameDocument = files1[i].DocName;
                    document.TypeDocument = files1[i].DocType;

                    cont.Content = files1[i].Content;
                    cont.Signature = files1[i].Signature;

                    int DocID = new int();
                    fileClient.AddEDoc((String)Session["sessionID"], (String)Session["sessionKey"], C_LINK_OFFERS, document, cont, ref DocID);
                }
            }
            //upload II section files
            if (files2 != null)
            {
                GovernmentPurchases.IUploadFiles.TEDocument document = new GovernmentPurchases.IUploadFiles.TEDocument();
                GovernmentPurchases.IUploadFiles.TEDContent cont = new GovernmentPurchases.IUploadFiles.TEDContent();

                for (int i = 0; i < files2.Length; i++)
                {
                    document.IDParent = offerID;
                    document.FileName = files2[i].FileName;
                    document.NameDocument = files2[i].DocName;
                    document.TypeDocument = files2[i].DocType;

                    cont.Content = files2[i].Content;
                    cont.Signature = files2[i].Signature;

                    int DocID = new int();
                    fileClient.AddEDoc((String)Session["sessionID"], (String)Session["sessionKey"], C_LINK_OFFERS, document, cont, ref DocID);
                }
            }

            AppLogger.Info(Session, "AddOffer: " + offerID);

            return Json(true);
        }
        public ActionResult AddAuction(AuctionInitData auctionInitData, AuctionGeneralInfo generalInfo, Contact[] contacts,
            string auctionRole, Lot[] lots, String content, String signature, File[] files)
        {
            TAuction auction = new TAuction();

            //заполняем шапку
            TAuctionHeader auctionHeader = new TAuctionHeader();
            auctionHeader.AuctionRegNumber = auctionInitData.AuctionRegNumber;
            auctionHeader.PurchaseName = auctionInitData.PurchaseName;
            auctionHeader.PurchaseSite = auctionInitData.PurchaseSite;
            auction.AuctionHeader = auctionHeader;
            //заполняем информацию о заказчике
            TMemberInfo memeberInfo = new TMemberInfo();
            memeberInfo.Address = auctionInitData.Address;
            memeberInfo.MemberRegNumber = auctionInitData.MemberRegNumber;
            memeberInfo.MemberType = int.Parse(auctionInitData.MemberType);
            memeberInfo.Name = auctionInitData.Name;
            memeberInfo.UNP = auctionInitData.UNP;
            auction.Customer = memeberInfo;

            //заполняем общую информацию об аукционе
            TAuctionInfo auctionInfo = new TAuctionInfo();
            auctionInfo.AddInfo = generalInfo.AddInfo;
            auctionInfo.CodeTender = generalInfo.RegNum;
            //currency code
            auctionInfo.Currency = generalInfo.CurrencyCode;
            //currency label
            auctionInfo.CurrencyAbb = generalInfo.Currency;
            auctionInfo.EndOfferDate = DateTimeUtils.DateTimeToDouble(DateTime.Parse(generalInfo.EndOfferDate.Trim().Replace(" ", string.Empty)));
            auctionInfo.ExpiryOfferDate = DateTimeUtils.DateTimeToDouble(DateTime.Parse(generalInfo.TenderEndDate.Trim().Replace(" ", string.Empty)));
            auctionInfo.FinanceType = generalInfo.FinanceType;
            auctionInfo.MemberRequires = generalInfo.MemberRequires;
            auctionInfo.PublishDate = DateTimeUtils.DateTimeToDouble(DateTime.Parse(generalInfo.RegDate.Trim().Replace(" ", string.Empty)));
            auctionInfo.QualificationRequires = generalInfo.QualificationRequires;
            if (generalInfo.SecurityPercent != null)
            {
                auctionInfo.SecurityPercent = double.Parse(generalInfo.SecurityPercent, System.Globalization.CultureInfo.InvariantCulture);
            }
            else
            {
                auctionInfo.SecurityPercent = 0;
            }
            auctionInfo.ServiceFee = double.Parse(auctionInitData.ServiceFee, System.Globalization.CultureInfo.InvariantCulture);
            auctionInfo.TotalCost = double.Parse(auctionInitData.TotalCost, System.Globalization.CultureInfo.InvariantCulture);
            auctionInfo.SubjectName = generalInfo.Name;
            auctionInfo.TenderDate = DateTimeUtils.DateTimeToDouble(DateTime.Parse(generalInfo.TenderDate.Trim().Replace(" ", string.Empty) + " " + generalInfo.TenderTime.Trim().Replace(" ", string.Empty)));
            auction.AuctionInfo = auctionInfo;

            //заполняем роль заказчика
            auction.CustomerRoleText = auctionRole;

            //заполняем контактные лица
            TContactPerson[] contactsPerson = new TContactPerson[contacts.Length];
            for (int i = 0; i < contacts.Length; i++)
            {
                TContactPerson contact = new TContactPerson();
                contact.Email = contacts[i].Email;
                contact.FIO = contacts[i].FIO;
                contact.Phone = contacts[i].Phones;
                contact.Fax= contacts[i].Fax;
                contact.AddInfo = contacts[i].OtherInfo;
                contactsPerson[i] = contact;
            }
            auction.ContactPersons = contactsPerson;

            TLotInfo[] lotsInfo = new TLotInfo[lots.Length];
            for (int i = 0; i < lots.Length; i++)
            {
                TLotInfo lotInfo = new TLotInfo();
                lotInfo.AddInfo = lots[i].OtherInfo;
                //lotInfo.AgreementConsent=
                //lotInfo.AuctionLotStatusText=
                lotInfo.Currency = generalInfo.CurrencyCode;
                lotInfo.CurrencyAbb = generalInfo.Currency;
                lotInfo.DeliveryDate = lots[i].Time;
                lotInfo.DeliveryPlace = lots[i].Place;
                lotInfo.Description = lots[i].Description;
                lotInfo.EdIzm = lots[i].EdIzmCode;
                lotInfo.EdIzmAbb = lots[i].EdIzm;
                lotInfo.FundingSource = int.Parse(lots[i].FinanceSourceCode);
                lotInfo.FundingSourceText = lots[i].FinanceSource;
                //lotInfo.LotID=
                lotInfo.LotVolume = double.Parse(lots[i].Value, System.Globalization.CultureInfo.InvariantCulture);
                lotInfo.NumLot = i + 1;
                //lotInfo.OfferLotStatusText=
                TOKRBRec[] okrb = new TOKRBRec[lots[i].OKRB.Length];
                for (int j = 0; j < lots[i].OKRB.Length;j++ )
                {
                    TOKRBRec okrbRec = new TOKRBRec();
                    okrbRec.OKRBCode = lots[i].OKRB[j].OKRBCode;
                    okrbRec.OKRBID = int.Parse(lots[i].OKRB[j].OKRBID);
                    okrbRec.OKRBName = lots[i].OKRB[j].OKRBName;
                    okrb[j] = okrbRec;
                }

                lotInfo.OKRBList = okrb;
                //lotInfo.PrefPercent = lots[i].
                //lotInfo.PrefReason = lots[i].
                //lotInfo.SecurityValue=
                lotInfo.StartPrice = double.Parse(lots[i].Price, System.Globalization.CultureInfo.InvariantCulture);
                lotInfo.VolumeMethod = lots[i].CalcMethod;

                lotsInfo[i] = lotInfo;
            }
            auction.Lots = lotsInfo;

            TEDContent eContent = new TEDContent();
            eContent.Content = content;
            eContent.Signature = signature;

            TAuthHeader header = new TAuthHeader();
            header.SessionID = (String)Session["sessionID"];
            header.SessionKey = (String)Session["sessionKey"];
            client.TAuthHeaderValue = header;

            int AuctionID = new int();
            client.AddAuction(auction, eContent, ref AuctionID);

            if (files != null)
            {
                GovernmentPurchases.IUploadFiles.IUploadFilesservice fileClient = new GovernmentPurchases.IUploadFiles.IUploadFilesservice();
                GovernmentPurchases.IUploadFiles.TEDocument document = new GovernmentPurchases.IUploadFiles.TEDocument();
                GovernmentPurchases.IUploadFiles.TEDContent cont = new GovernmentPurchases.IUploadFiles.TEDContent();

                for (int i = 0; i < files.Length; i++)
                {

                    document.IDParent = AuctionID;
                    document.FileName = files[i].FileName;
                    document.NameDocument = files[i].DocName;
                    document.TypeDocument = files[i].DocType;

                    cont.Content = files[i].Content;
                    cont.Signature = files[i].Signature;

                    int DocID = new int();
                    fileClient.AddEDoc((String)Session["sessionID"], (String)Session["sessionKey"], C_LINK_AUCTIONS, document, cont, ref DocID);
                }
            }

            client.LockAuctionForEdit(AuctionID, 0);

            return Json(true);
        }