Пример #1
0
        public void CRMcreateOrUpdateThesis(List <ThesisModel> ThesisList, IOrganizationService service, ColumnSet colsThesis)
        {
            foreach (var item in ThesisList)
            {
                new_opinnytety thesis = new new_opinnytety
                {
                    Name            = item.aihe,
                    OhosId          = item.thesisID,
                    Ohjaaja         = item.ohjaaja,
                    OpiskelijaID    = item.opiskelijaID,
                    Koulutusohjelma = item.koulutusohjelma,
                    Toimeksiantaja  = item.ta_nimi,
                    Yhteyshenkilo   = item.yhteyshenkilo
                };

                var query = new QueryExpression("new_opinnytety");
                query.Criteria.AddCondition("new_name", ConditionOperator.Equal, item.aihe);
                query.Criteria.AddCondition("new_ohosid", ConditionOperator.Equal, item.thesisID);
                query.ColumnSet = colsThesis;
                EntityCollection users = service.RetrieveMultiple(query);
                if (users.Entities.Count() > 0)
                {
                    query.Criteria.AddCondition("new_yhteyshenkilo", ConditionOperator.Equal, item.yhteyshenkilo);
                    users = service.RetrieveMultiple(query);
                    thesis.OpinnytetyId = (Guid)users.Entities.FirstOrDefault().Attributes["new_opinnytetyid"];
                    if (users.Entities.Count() > 0)
                    {
                        query.Criteria.AddCondition("new_ohjaaja", ConditionOperator.Equal, item.ohjaaja);
                        users = service.RetrieveMultiple(query);
                        if (users.Entities.Count() == 0)
                        {
                            service.Update(thesis);
                        }
                    }
                    else
                    {
                        service.Update(thesis);
                    }
                }
                else
                {
                    service.Create(thesis);
                }
            }
        }
Пример #2
0
        //<snippetCRUDOperations1>
        /// <summary>
        /// This method performs entity create, retrieve, and update operations.
        /// The delete operation is handled in the DeleteRequiredrecords() method.
        /// </summary>
        /// <param name="serviceProxy">An established connection to the Organization web service.</param>
        /// <param name="records">A collection of entity records created by this sample.</param>
        public void Run(OrganizationServiceProxy serviceProxy, EntityReferenceCollection records, CheckBox checkBox1, CheckBox checkBox2, CheckBox checkBox3, CheckBox checkBox4, CheckBox checkBox5)
        {
            // Enable early-bound entity types. This enables use of IntelliSense in Visual Studio
            // and avoids spelling errors in attribute names when using the Entity property bag.
            serviceProxy.EnableProxyTypes();

            // Here we will use the interface instead of the proxy object.
            IOrganizationService service = (IOrganizationService)serviceProxy;



            Form1 newForm = new Form1();


            //Console.Write("{0} {1} created, ", account.LogicalName, account.Name);

            // Retrieve the account containing several of its attributes. This results in
            // better performance compared to retrieving all attributes.
            ColumnSet colsAccount = new ColumnSet(
                new String[] { "name", "emailaddress1", "address1_name", "accountid", "modifiedon" /*,"address1_postalcode","address1_city"*/ });
            ColumnSet colsContact = new ColumnSet(
                new String[] { "fullname", "emailaddress1", "telephone1", "parentcustomerid", "firstname", "lastname" });
            ColumnSet colsThesis = new ColumnSet(
                new String[] { "new_name", "new_ohosid", "new_yhteyshenkilo", "new_ohjaaja" });
            QueryExpression qe              = new QueryExpression();
            QueryExpression qa              = new QueryExpression();
            QueryExpression qcontact        = new QueryExpression();
            QueryExpression queryexpression = new QueryExpression();

            qe.EntityName              = "account";
            qa.EntityName              = "opportunity";
            qcontact.EntityName        = "contact";
            queryexpression.EntityName = "new_opinnytety";


            qe.ColumnSet       = colsAccount;
            qcontact.ColumnSet = colsContact;



            List <AccountModel> AccountList = new List <AccountModel>();

            AccountList = Accounts();


            List <ThesisModel> ThesisList = new List <ThesisModel>();

            ThesisList = Thesis();
            List <TopicModel> TopicList = new List <TopicModel>();

            TopicList = Topics();

            List <ContactModel> ContactList = new List <ContactModel>();

            ContactList = Contacts();

            EntityCollection econtact = service.RetrieveMultiple(qcontact);
            EntityCollection eaccount = service.RetrieveMultiple(qe);



            new_opinnytety new_Opinnytety = new new_opinnytety();



            //ALLA OLEVA FUNKTIO TOIMII, POISSA KÄYTÖSTÄ SEURAAVAN FUNKTION TEKOA VARTEN
            //checkCreateAndUpdateClients(AccountList, ec, service); Tämä oli huono funktio.
            if (checkBox1.Checked)
            {
                CRMcreateOrUpdateClients(AccountList, service, colsAccount); //Tämä hyvä funktio, tämä toimii
            }
            //ALLA OLEVA FUNKTIO TOIMII
            if (checkBox2.Checked)
            {
                CRMcreateOrUpdateContacts(ContactList, service, colsContact); //Tämä hyvä funktio, tämä toimii
            }
            //ALLA OLEVA FUNKTIO TOIMII
            if (checkBox3.Checked)
            {
                CRMcreateOrUpdateThesis(ThesisList, service, colsThesis); //Tämä hyvä funktio, tämä toimii
            }
            if (checkBox4.Checked)
            {
                OHOScreateOrUpdateClients(eaccount);
            }
            if (checkBox5.Checked)
            {
                OHOScreateOrUpdateContacts(econtact);
            }
        }