Example #1
0
        public void Save(string listUrl)
        {
            SPWeb web = SPContext.Current.Web;
            SPList targetList = web.GetList(string.Format("{0}/{1}", web.Url, listUrl));
            try
            {

                web.AllowUnsafeUpdates = true;
                AddListItemCommand addListItemCommand = new AddListItemCommand(ContentTypes.CONTACT_REQUEST_ID, _PropertyBag, targetList, web);
                addListItemCommand.Execute();
                _ID = addListItemCommand.ListItem.ID;
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                web.AllowUnsafeUpdates = false;
            }

        }
Example #2
0
        public void Save(string contextUrl, string listUrl)
        {
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (SPSite site = new SPSite(contextUrl))
                {
                    using (SPWeb web = site.OpenWeb())
                    {
                        SPList targetList = web.GetList(string.Format("{0}/{1}", web.Url, listUrl));
                        web.AllowUnsafeUpdates = true;

                        AddListItemCommand addListItemCommand = new AddListItemCommand(ContentTypes.CONTACT_REQUEST_ID, _PropertyBag, targetList, web);
                        addListItemCommand.Execute();

                        _ID = addListItemCommand.ListItem.ID;
                        web.AllowUnsafeUpdates = false;

                        SPWeb rootWeb = site.RootWeb;
                        MailConfigEntity mailConfigurationSettings = MailConfigEntity.Get(rootWeb);

                        AspNetMailHelper aspNetMailHelper = default(AspNetMailHelper);
                        if (mailConfigurationSettings.UseSharepointDefaultConfig)
                        {
                            aspNetMailHelper = new AspNetMailHelper(SPAdministrationWebApplication.Local.OutboundMailServiceInstance.Server.Address);
                        }
                        else
                        {
                            aspNetMailHelper = new AspNetMailHelper(mailConfigurationSettings.MailServerAddress, mailConfigurationSettings.Port, mailConfigurationSettings.UseSSL
                                , mailConfigurationSettings.UserName, mailConfigurationSettings.Password);
                        }

                        string messageBody =
                            string.Format("Buen dia.\nSe ha recibido un registro de solicitd de contacto de parte de {0} {1}.\nPara ver la informacion completa del registro siga esta url\n{2}\nSaludos.\nEl equipo web de IO."
                            , this._FirstName, this._LastName, this._LastName, string.Format("{0}/_layouts/15/listform.aspx?PageType=4&ListId={1}&ID={2}&ContentTypeID={3}", web.Url, addListItemCommand.List.ID, addListItemCommand.ListItem.ID, addListItemCommand.ListItem.ContentTypeId));

                        aspNetMailHelper.SendTextMail(this._Email, mailConfigurationSettings.InboundMailAddress, "Registro de Solicitud de Contacto", messageBody);
                    }
                }
            });

        }