Beispiel #1
0
        public static bool EmailData(List <Employee> PendingEmployee, string siteUrl, string listName)
        {
            bool retValue = false;

            try
            {
                using (MSC.ClientContext context = CustomSharePointUtility.GetContext(siteUrl))
                {
                    //List<Mailing> varx = new List<Mailing>();

                    MSC.List list = context.Web.Lists.GetByTitle(listName);

                    MSC.ListItem listItem = null;

                    MSC.ListItemCreationInformation itemCreateInfo = new MSC.ListItemCreationInformation();
                    listItem = list.AddItem(itemCreateInfo);


                    // MSC.UserCollection users = new MSC.UserCollection();
                    //MSC.FieldUserValue fieldUserValue = new MSC.FieldUserValue();


                    MSC.FieldUserValue[] userValueCollection = new MSC.FieldUserValue[PendingEmployee.Count];
                    for (var i = 0; i < PendingEmployee.Count; i++)
                    {
                        MSC.FieldUserValue fieldUserVal = new MSC.FieldUserValue();
                        fieldUserVal.LookupId = Convert.ToInt32(PendingEmployee[i].EmployeeID);
                        userValueCollection.SetValue(fieldUserVal, i);
                    }


                    //var _From = "";
                    var _To = "";
                    //var _Cc = "";
                    var _Body    = "";
                    var _Subject = "";

                    _To = "1247";

                    _Subject = "Sales Estimate is not submitted";
                    _Body   += "Dear User, <br><br>This is to inform you that still your Sales Estimate is not submitted kindly fill and submit on priority.<br><br>Kindly click on below link for submit estimate";
                    _Body   += "<br><a href=" + siteUrl + "/SitePages/NewRequest.aspx>Submit Estimate</ a>";



                    listItem["ToUser"]      = userValueCollection;
                    listItem["SubjectDesc"] = _Subject;
                    listItem["BodyDesc"]    = _Body;
                    listItem.Update();


                    try
                    {
                        context.ExecuteQuery();
                        retValue = true;
                    }
                    catch (Exception ex)
                    {
                        CustomSharePointUtility.WriteLog(string.Format("Error in  InsertUpdate_EmployeeMaster ( context.ExecuteQuery();): Error ({0}) ", ex.Message));
                        return(false);
                        //continue;
                    }
                }

                //        }
                //    }
                //}

                //}
            }

            catch (Exception ex)
            {
                CustomSharePointUtility.WriteLog(string.Format("Error in  InsertUpdate_EmployeeMaster: Error ({0}) ", ex.Message));
            }
            return(retValue);
        }