Exemple #1
0
        public string InsertEmailSubjectSerial(string subject, string status, SubjectTopic subjectTopicValue, SubjectType subjectTypeValue, Microsoft.Office.Interop.Outlook.MailItem mailItem)
        {
            try
            {
                Guid   g       = Guid.NewGuid();
                string siteUrl = Properties.Settings.Default.ClientContextUrl;
                using (var clientContext = new AuthenticationManager().GetAppOnlyAuthenticatedContext(siteUrl, Properties.Settings.Default.ClientId, Properties.Settings.Default.ClientSecret))
                {
                    Web            oWebsite = clientContext.Web;
                    ListCollection collList = oWebsite.Lists;

                    SP.List oList = collList.GetByTitle("EmailSubject_Serial");
                    ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();

                    ListItem oListItem = oList.AddItem(itemCreateInfo);

                    // type section//////////////////////////////////////
                    FieldLookupValue typeFieldLookupValue = new FieldLookupValue();  //GetLookupFieldValue(subjectTypeValue.Title, "EmailSubject_Types");
                    typeFieldLookupValue.LookupId = subjectTypeValue.ID;
                    if (typeFieldLookupValue != null)
                    {
                        oListItem["ParentType"] = typeFieldLookupValue;
                    }
                    ////////////////////////////////////////////////////////////////
                    // tpoic section//////////////////////////////////////
                    FieldLookupValue topicFieldLookupValue = new FieldLookupValue();
                    topicFieldLookupValue.LookupId = subjectTopicValue.ID;
                    //FieldLookupValue topicFieldLookupValue = GetLookupFieldValue(subjectTopicValue.Title, "EmailSubject_Topics");
                    if (topicFieldLookupValue != null)
                    {
                        oListItem["ParentTopic"] = topicFieldLookupValue;
                    }
                    ////////////////////////////////////////////////////////////////
                    // status section//////////////////////////////////////
                    oListItem["Status"] = status; //Pending Comfirmed
                    ///////////////////////////////////////////////////////
                    // user section//////////////////////////////////////////
                    var usr = getEnsureUser(mailItem);
                    if (usr == null)
                    {
                        return("");
                    }

                    Microsoft.SharePoint.Client.FieldUserValue _userValue = new Microsoft.SharePoint.Client.FieldUserValue();
                    _userValue.LookupId = usr.Id;
                    oListItem["User"]   = _userValue;
                    ///////////////////////////////////////////////////////////////
                    // title section///////////////////////////////////////////////
                    oListItem["Title"] = g.ToString();
                    ////////////////////////////////////////////////////////////////
                    oListItem.Update();

                    clientContext.ExecuteQuery();

                    int id = oListItem.Id;

                    string subjectToReturn = "";
                    oListItem["Title"] = string.Format("[{0:D}-{1:D}-{2:D}] {3:D}", subjectTopicValue.Code, subjectTypeValue.Code, id, subject);
                    subjectToReturn    = string.Format("[{0:D}-{1:D}-{2:D}] {3:D}", subjectTopicValue.Code, subjectTypeValue.Code, id, subject);

                    oListItem.Update();

                    clientContext.ExecuteQuery();

                    return(subjectToReturn);
                }
            }
            catch (Exception ex)
            {
                return("");

                throw new Exception(ex.ToString());
            }
        }
 public MyControlEventArgs(bool result, string subject, SubjectTopic subjectTopicValue, SubjectType subjectTypeValue)
 {
     _IsOK              = result;
     _Subject           = subject;
     _SubjectTopicValue = subjectTopicValue;
     _SubjectTypeValue  = subjectTypeValue;
 }