Ejemplo n.º 1
0
        /// <summary>
        /// Get content update for current user from last login
        /// </summary>
        /// <returns></returns>
        public ContentUpdateWidget GetContentUpdates()
        {
            if (WorkContext.CurrentUser != null && WorkContext.CurrentUser.LastTimeGettingUpdate.HasValue)
            {
                var logs = _subscriptionLogService.GetLogs(null, WorkContext.CurrentUser.LastTimeGettingUpdate.Value,
                                                           SubscriptionEnums.SubscriptionModule.Page);

                var pageIds =
                    logs.Select(l => l.Parameters)
                    .ToList()
                    .Select(p => SerializeUtilities.Deserialize <SubscriptionPageParameterModel>(p).Id);

                var pages = _pageService.Maps(_pageService.Fetch(p => pageIds.Contains(p.Id))).ToList();

                var pageLogs = logs.GroupBy(l => l.Parameters).ToList().Select(l => new PageSubscriptionLogModel
                {
                    Page =
                        pages.FirstOrDefault(
                            p => p.Id == SerializeUtilities.Deserialize <SubscriptionPageParameterModel>(l.Key).Id) ??
                        new PageModel(),
                    Logs = l.Select(i => new SubscriptionLogItem(i)).ToList()
                }).ToList();


                return(new ContentUpdateWidget
                {
                    TotalChanges = pageLogs.Count,
                    TotalLogs = pageLogs.Sum(l => l.Logs.Count),
                    PageLogs = pageLogs
                });
            }

            return(new ContentUpdateWidget());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Get page subscription email content
        /// </summary>
        /// <param name="emailModels"></param>
        /// <param name="template"></param>
        /// <param name="isAnythingChanged"></param>
        /// <returns></returns>
        private string GetPageSubscriptionEmailContent(List <SubscriptionEmailModel> emailModels,
                                                       SubscriptionTemplate template, ref bool isAnythingChanged)
        {
            var pageService = HostContainer.GetInstance <IPageService>();
            var subscriptionTemplateService = HostContainer.GetInstance <ISubscriptionTemplateService>();

            // Get a list of pageId in SubscriptionEmailModel
            var pageIds =
                emailModels.Select(l => SerializeUtilities.Deserialize <SubscriptionPageParameterModel>(l.Parameters).Id)
                .ToList();

            // Map that list of pageId to list of PageModel
            var pages = pageService.Maps(pageService.Fetch(p => pageIds.Contains(p.Id))).ToList();

            // Select a list of PageSubscriptionEmailModel from SubscriptionEmailModel and PageModel
            var model = emailModels.Select(m => new PageSubscriptionEmailModel
            {
                SubscriptionId = m.SubscriptionId,
                Page           =
                    pages.FirstOrDefault(
                        p => p.Id == SerializeUtilities.Deserialize <SubscriptionPageParameterModel>(m.Parameters).Id) ??
                    new PageModel(),
                Logs = m.Logs
            }).ToList();

            // Enable flag for sending email
            if (model.Any(e => e.Logs.Any()))
            {
                isAnythingChanged = true;
            }

            return(subscriptionTemplateService.ParseSubscription(template.Module, model).Body);
        }
Ejemplo n.º 3
0
        public EmailLogDetailModel(EmailLog emailLog)
            : this()
        {
            Id       = emailLog.Id;
            Priority = emailLog.Priority;
            From     = emailLog.From;
            FromName = emailLog.FromName;
            To       = emailLog.To;
            ToName   = emailLog.ToName;
            if (!string.IsNullOrEmpty(emailLog.CC))
            {
                CcList = emailLog.CC.Split(';').ToList();
            }
            if (!string.IsNullOrEmpty(emailLog.Bcc))
            {
                BccList = emailLog.Bcc.Split(';').ToList();
            }
            Subject        = emailLog.Subject;
            SentTries      = emailLog.SentTries;
            SentOn         = emailLog.SentOn;
            Body           = emailLog.Body;
            EmailAccountId = emailLog.EmailAccountId;
            if (!string.IsNullOrEmpty(emailLog.Message))
            {
                Logs = SerializeUtilities.Deserialize <List <EmailSendingLog> >(emailLog.Message);
            }

            RecordOrder  = emailLog.RecordOrder;
            Created      = emailLog.Created;
            CreatedBy    = emailLog.CreatedBy;
            LastUpdate   = emailLog.LastUpdate;
            LastUpdateBy = emailLog.LastUpdateBy;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Get subscription by module and parameters
        /// </summary>
        /// <param name="module"></param>
        /// <param name="email"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public SubscriptionModel GetSubscription(SubscriptionEnums.SubscriptionModule module, string email,
                                                 string parameters)
        {
            if (parameters != null)
            {
                var data = Fetch(s => s.Active && s.Module == module && s.Email.Equals(email)).ToList();

                if (data.Any())
                {
                    var subscriptions = data.Select(s => new SubscriptionModel(s));

                    switch (module)
                    {
                    case SubscriptionEnums.SubscriptionModule.Page:
                        var param        = SerializeUtilities.Deserialize <SubscriptionPageParameterModel>(parameters);
                        var subscription =
                            subscriptions.FirstOrDefault(
                                s => ((SubscriptionPageParameterModel)s.Parameters).Id == param.Id);
                        if (subscription != null)
                        {
                            return(subscription);
                        }
                        break;
                    }
                }
            }

            return(null);
        }
Ejemplo n.º 5
0
        private EmailQueue GetEmail(FormType type, string jsonData, string employeeEmail, string employeeName)
        {
            var email = new EmailQueue()
            {
                From         = "",
                FromName     = "Hệ Thống",
                To           = employeeEmail,
                ToName       = employeeName,
                Subject      = "",
                CreatedBy    = "system",
                Created      = DateTime.Now,
                RecordActive = true,
            };
            var    data             = new object();
            string resourceName     = string.Empty;
            string templateFilePath = string.Empty;

            switch (type)
            {
            case FormType.Admission:
                email.Subject = "Đăng kí nhập học";
                data          = SerializeUtilities.Deserialize <AdmissionData>(jsonData);
                resourceName  = "Kent.Business.Core.EmailTemplate.Admission.cshtml";
                break;

            case FormType.Advisory:
                email.Subject = "Đăng kí tư vấn";
                data          = SerializeUtilities.Deserialize <AdvisoryData>(jsonData);
                resourceName  = "Kent.Business.Core.EmailTemplate.Advisory.cshtml";
                break;

            case FormType.Alumni:
                email.Subject = "Thông tin cựu sinh viên";
                data          = SerializeUtilities.Deserialize <AlumniData>(jsonData);
                resourceName  = "Kent.Business.Core.EmailTemplate.Alumni.cshtml";
                break;

            case FormType.Contact:
                email.Subject = "Liên hệ";
                data          = SerializeUtilities.Deserialize <ContactData>(jsonData);
                resourceName  = "Kent.Business.Core.EmailTemplate.Contact.cshtml";
                break;

            case FormType.Visit:
                email.Subject = "Đăng kí tham quan";
                data          = SerializeUtilities.Deserialize <VisitSchoolData>(jsonData);
                resourceName  = "Kent.Business.Core.EmailTemplate.VisitSchool.cshtml";
                break;
            }
            var assembly = Assembly.GetExecutingAssembly();

            using (Stream stream = assembly.GetManifestResourceStream(resourceName))
                using (StreamReader reader = new StreamReader(stream))
                {
                    string templateStr = reader.ReadToEnd();
                    email.Body = Engine.Razor.RunCompile(templateStr, "templateKey", null, data);
                }

            return(email);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Search notified contacts
        /// </summary>
        /// <param name="notificationId"></param>
        /// <returns></returns>
        private IQueryable <NotifiedContactModel> SearchNotifiedContacts(int notificationId)
        {
            var notification = FetchFirst(n => n.Id == notificationId);

            return
                (SerializeUtilities.Deserialize <List <NotifiedContactModel> >(notification.NotifiedContacts).AsQueryable());
        }
Ejemplo n.º 7
0
        public ActionResult AdvisoryListing(string keyword, bool?export)
        {
            var listing = _formServices.GetListForms(FormType.Advisory, keyword);
            List <AdvisoryData> dataLst = listing
                                          .Select(d =>
            {
                var data = SerializeUtilities.Deserialize <AdvisoryModel>(d.Data);
                return(new AdvisoryData()
                {
                    Name = data.Name,
                    Email = data.Email,
                    PhoneNumber = data.PhoneNumber,
                    DateCreated = d.DateSubmit.Value
                });
            }).ToList();

            if (export.HasValue && export.Value)
            {
                var gv = new GridView();
                gv.DataSource = dataLst;
                gv.DataBind();
                Response.ClearContent();
                Response.Buffer = true;
                Response.AddHeader("content-disposition", "attachment; filename=Danh sách tư vấn.xls");
                Response.ContentType = "application/ms-excel";
                Response.Charset     = "";
                StringWriter   objStringWriter   = new StringWriter();
                HtmlTextWriter objHtmlTextWriter = new HtmlTextWriter(objStringWriter);
                gv.RenderControl(objHtmlTextWriter);
                Response.Output.Write(objStringWriter.ToString());
                Response.Flush();
                Response.End();
            }
            return(View(dataLst));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Get access token
        /// </summary>
        /// <param name="clientId"></param>
        /// <param name="secretKey"></param>
        /// <param name="code"></param>
        /// <param name="callbackUrl"></param>
        /// <param name="expiredDate"></param>
        /// <returns></returns>
        public static string GetAccessToken(string clientId, string secretKey, string code, string callbackUrl, out DateTime expiredDate)
        {
            var accessTokenUrl = GetLinkedInAccessTokenUrl(clientId, secretKey, code, callbackUrl);
            var response       = SerializeUtilities.Deserialize <LinkedInAccessToken>(WebUtilities.GetRequest(accessTokenUrl));

            expiredDate = DateTime.UtcNow.AddSeconds(response.expires_in);
            return(response.access_token);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Get url request
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="url"></param>
        /// <returns></returns>
        public static T GetRequest <T>(string url) where T : class
        {
            using (var client = new WebClient())
            {
                var content = client.DownloadString(url);

                return(SerializeUtilities.Deserialize <T>(content));
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Get contact search details models
        /// </summary>
        /// <param name="queries"></param>
        /// <returns></returns>
        public IEnumerable <ContactSearchDetailsModel> GetContactSearchDetailsModels(string queries)
        {
            if (!string.IsNullOrEmpty(queries))
            {
                // Deserialize contact queries string to object
                var contactSearchModels = SerializeUtilities.Deserialize <List <ContactSearchModel> >(queries);
                return
                    (contactSearchModels.Select(contactSearchModel => new ContactSearchDetailsModel(contactSearchModel)));
            }

            return(new List <ContactSearchDetailsModel>());
        }
        public FormComponentFieldManageModel(FormComponentField formComponentField)
            : this()
        {
            Id         = formComponentField.Id;
            Name       = formComponentField.Name;
            Attributes = SerializeUtilities.Deserialize <FormComponentFieldAttributeModel>(formComponentField.Attributes);

            FormComponentId = formComponentField.FormComponentId;
            FormComponents  = _formComponentService.GetFormComponents(formComponentField.FormComponentId);

            RecordOrder = formComponentField.RecordOrder;
        }
Ejemplo n.º 12
0
        public WhereClause Generate(bool search, string filters, Type targetSearchType)
        {
            _formatObjects = new List <object>();

            return(new WhereClause
            {
                Clause = search && !String.IsNullOrEmpty(filters)
                    ? ParseFilter(SerializeUtilities.Deserialize <JqGridFilter>(filters), targetSearchType).ToString()
                    : String.Empty,
                FormatObjects = _formatObjects.ToArray()
            });
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Get fields
        /// </summary>
        /// <param name="fields"></param>
        /// <returns></returns>
        private dynamic GetFields(IEnumerable <FormComponentFieldBase> fields)
        {
            //TODO: update here using http://stackoverflow.com/questions/26874014/serialize-data-to-json-string-with-dynamic-property-names
            const string jsonString = @"
""{0}"" : {1}";
            var          json       = string.Join(",", fields.Select(field => string.Format(jsonString, field.Name, field.Attributes)));

            json = string.Format(@"
{{{0}}}", json);

            return(SerializeUtilities.Deserialize <dynamic>(json));
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Get all contacts that fit queries
        /// </summary>
        /// <param name="queries"></param>
        /// <returns></returns>
        public IQueryable <Contact> GetContacts(string queries)
        {
            // If queries is empty, return empty list
            if (string.IsNullOrEmpty(queries))
            {
                return(new List <Contact>().AsQueryable());
            }

            var contactSearchModels = SerializeUtilities.Deserialize <List <ContactSearchModel> >(queries);

            return(_contactService.SearchContacts(contactSearchModels));
        }
Ejemplo n.º 15
0
 public WidgetTemplateManageModel(WidgetTemplate widgetTemplate)
 {
     Id                = widgetTemplate.Id;
     Name              = widgetTemplate.Name;
     Content           = widgetTemplate.Content;
     FullContent       = widgetTemplate.FullContent;
     Shortcuts         = SerializeUtilities.Deserialize <List <Shortcut> >(widgetTemplate.Widgets);
     Script            = widgetTemplate.Script;
     Style             = widgetTemplate.Style;
     DataType          = widgetTemplate.DataType;
     IsDefaultTemplate = widgetTemplate.IsDefaultTemplate;
     Widget            = widgetTemplate.Widget;
 }
Ejemplo n.º 16
0
 public WidgetTemplateManageModel(WidgetTemplateLog log)
     : this()
 {
     Id                = log.TemplateId;
     Name              = log.Name;
     Shortcuts         = SerializeUtilities.Deserialize <List <Shortcut> >(log.Widgets);
     Script            = log.Script;
     Style             = log.Style;
     Content           = log.Content;
     FullContent       = log.FullContent;
     DataType          = log.DataType;
     IsDefaultTemplate = log.WidgetTemplate.IsDefaultTemplate;
     Widget            = log.WidgetTemplate.Widget;
 }
Ejemplo n.º 17
0
        /// <summary>
        /// Save contact group to notification
        /// </summary>
        /// <param name="model"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public ContactStatisticModel SaveContactGroup(ContactGroupSetupModel model, out string message)
        {
            var notification = GetById(model.Id);

            if (notification != null)
            {
                // Deserialize contact queries string in notification model to object
                var contactSearchModels = string.IsNullOrEmpty(notification.ContactQueries)
                    ? new List <ContactSearchModel>()
                    : SerializeUtilities.Deserialize <List <ContactSearchModel> >(notification.ContactQueries);

                // Number of contacts before new queries is added
                var totalExistingContacts = _contactService.SearchContacts(contactSearchModels).Count();

                // Add new queries
                contactSearchModels.Add(model.ContactSearchModel);

                // Number of contact after new queries is added
                var totalContactsAfterAdded = _contactService.SearchContacts(contactSearchModels).Count();

                // Number of contact in new queries
                var totalNewContactsExpected = _contactService.SearchContacts(model.ContactSearchModel).Count();

                // Serialize contact queries and assign to notification model
                notification.ContactQueries = SerializeUtilities.Serialize(contactSearchModels);

                // Save new notification
                var response = Update(notification);
                if (response.Success)
                {
                    message = string.Format("{0} duplicated contact(s). {1} contact(s) added successfully.",
                                            totalNewContactsExpected + totalExistingContacts - totalContactsAfterAdded,
                                            totalContactsAfterAdded - totalExistingContacts);

                    return(new ContactStatisticModel
                    {
                        ExistedContacts = totalNewContactsExpected + totalExistingContacts - totalContactsAfterAdded,
                        NewContacts = totalContactsAfterAdded - totalExistingContacts,
                        TotalContacts = totalContactsAfterAdded,
                        ContactSearchDetailsModel = new ContactSearchDetailsModel(model.ContactSearchModel)
                    });
                }

                message = T("Notification_Message_SavingContactGroupFailure");
                return(null);
            }
            message = T("Notification_Message_ObjectNotFound");
            return(null);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Get group rotating image manage model
        /// </summary>
        /// <param name="id">the group id</param>
        /// <returns></returns>
        public GroupManageSettingModel GetGroupManageSettingModel(int id)
        {
            var group = GetById(id);

            if (group != null)
            {
                var model = new GroupManageSettingModel
                {
                    Id = id,
                    GroupSettingModel = SerializeUtilities.Deserialize <GroupSettingModel>(@group.Settings)
                };
                return(model);
            }
            return(null);
        }
Ejemplo n.º 19
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            var localizedResourceService = HostContainer.GetInstance <IEzCMSLocalizedResourceService>();

            switch (Module)
            {
            case NotificationEnums.NotificationModule.Page:

                if (SerializeUtilities.Deserialize <NotificationPageParameterModel>(Parameters).Id == 0)
                {
                    yield return(new ValidationResult(localizedResourceService.T("Notification_Message_InvalidParameters"), new[] { "Parameters" }));
                }
                break;
            }
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Count contacts
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ResponseModel CountContacts(ContactSearchModel model)
        {
            var notification = GetById(model.NotificationId);

            if (notification != null)
            {
                // Deserialize contact queries string in notification model to object
                var contactSearchModels = string.IsNullOrEmpty(notification.ContactQueries)
                    ? new List <ContactSearchModel>()
                    : SerializeUtilities.Deserialize <List <ContactSearchModel> >(notification.ContactQueries);

                // Number of contacts before new queries is added
                var totalExistingContacts = _contactService.SearchContacts(contactSearchModels).Count();

                // Add new queries
                contactSearchModels.Add(model);

                // Number of contact after new queries is added
                var totalContactsAfterAdded = _contactService.SearchContacts(contactSearchModels).Count();

                // Number of contact in new queries
                var totalNewContactsExpected = _contactService.SearchContacts(model).Count();

                // Serialize contact queries and assign to notification model
                notification.ContactQueries = SerializeUtilities.Serialize(contactSearchModels);

                var contactStatistic = new ContactStatisticModel
                {
                    ExistedContacts = totalNewContactsExpected + totalExistingContacts - totalContactsAfterAdded,
                    NewContacts     = totalContactsAfterAdded - totalExistingContacts,
                    TotalContacts   = totalContactsAfterAdded
                };

                var response = new ResponseModel
                {
                    Success = true,
                    Data    = contactStatistic
                };

                return(response);
            }

            return(new ResponseModel
            {
                Success = false,
                Message = T("Notification_Message_ObjectNotFound")
            });
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Get page subscription result from action
        /// </summary>
        /// <param name="subscriptionAction"></param>
        /// <param name="subscription"></param>
        /// <returns></returns>
        private ResponseModel GetPageSubscriptionResult(SubscriptionEnums.SubscriptionAction subscriptionAction,
                                                        Subscription subscription)
        {
            ResponseModel response;

            var parameters = SerializeUtilities.Deserialize <SubscriptionPageParameterModel>(subscription.Parameters);
            var page       = _pageService.GetById(parameters.Id);

            if (page != null)
            {
                switch (subscriptionAction)
                {
                case SubscriptionEnums.SubscriptionAction.View:
                    response = new ResponseModel
                    {
                        Success = true,
                        Data    = "/" + page.FriendlyUrl
                    };
                    break;

                case SubscriptionEnums.SubscriptionAction.Remove:
                    var subscriptionManageModel = new SubscriptionManageModel(subscription);
                    response = RemoveRegistration(subscriptionManageModel);
                    if (response.Success)
                    {
                        response.Message = T("Subscription_Message_PageUnsubscribeSuccessfully");
                    }
                    break;

                default:
                    response = new ResponseModel
                    {
                        Success = false,
                        Message = T("Subscription_Message_WrongSubscription")
                    };
                    break;
                }
            }
            else
            {
                response = new ResponseModel
                {
                    Success = false,
                    Message = T("Subscription_Message_WrongSubscription")
                };
            }
            return(response);
        }
Ejemplo n.º 22
0
        private void Init(User user)
        {
            UserId = user.Id;

            var setting = string.IsNullOrEmpty(user.Settings)
                ? new UserSettingModel()
                : SerializeUtilities.Deserialize <UserSettingModel>(user.Settings);

            AdminPageSize = setting.AdminPageSize;
            TimeZone      = setting.TimeZone;

            Culture  = setting.Culture;
            Cultures = _languageService.GetLanguages();

            TimeZones = TimeZoneUtilities.GetTimeZones(TimeZone);
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Search logs
        /// </summary>
        /// <param name="si"></param>
        /// <param name="emailLogId"></param>
        /// <returns></returns>
        public JqGridSearchOut SearchLogs(JqSearchIn si, int emailLogId)
        {
            var emailLog = GetById(emailLogId);
            var logs     = new List <EmailSendingLog>();

            if (emailLog != null && !string.IsNullOrEmpty(emailLog.Message))
            {
                logs = SerializeUtilities.Deserialize <List <EmailSendingLog> >(emailLog.Message);
            }

            if (logs == null)
            {
                logs = new List <EmailSendingLog>();
            }

            return(si.Search(logs.AsQueryable()));
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Count contacts in a notification
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int CountContacts(int id)
        {
            var notification = GetById(id);

            if (notification != null)
            {
                // Deserialize contact queries string in notification model to object
                var contactSearchModels = string.IsNullOrEmpty(notification.ContactQueries)
                    ? new List <ContactSearchModel>()
                    : SerializeUtilities.Deserialize <List <ContactSearchModel> >(notification.ContactQueries);

                // Number of contacts in notified contact queries
                return(_contactService.SearchContacts(contactSearchModels).Count());
            }

            return(0);
        }
Ejemplo n.º 25
0
        public SubscriptionModel(Subscription subscription)
            : this()
        {
            Id     = subscription.Id;
            Email  = subscription.Email;
            Module = subscription.Module;
            switch (Module)
            {
            case SubscriptionEnums.SubscriptionModule.Page:
                Parameters = SerializeUtilities.Deserialize <SubscriptionPageParameterModel>(subscription.Parameters);
                break;
            }

            DeactivatedDate = subscription.DeactivatedDate;

            RecordOrder  = subscription.RecordOrder;
            Created      = subscription.Created;
            CreatedBy    = subscription.CreatedBy;
            LastUpdate   = subscription.LastUpdate;
            LastUpdateBy = subscription.LastUpdateBy;
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Build html for page module
        /// </summary>
        /// <param name="notification"></param>
        /// <param name="notificationTemplate"></param>
        /// <param name="contact"></param>
        /// <returns></returns>
        private string GetPageNotificationEmailContent(Notification notification, NotificationTemplate notificationTemplate, Contact contact)
        {
            var pageService = HostContainer.GetInstance <IPageService>();
            var notificationTemplateService = HostContainer.GetInstance <INotificationTemplateService>();

            // Get page parameters in notification model
            var pageParameters = SerializeUtilities.Deserialize <NotificationPageParameterModel>(notification.Parameters);

            // Map that page parameters to page model
            var page = pageService.GetById(pageParameters.Id);

            // Create a page notification email model from page model
            var model = new NotificationPageEmailModel
            {
                NotificationId = notification.Id,
                Contact        = new ContactModel(contact),
                Page           = page != null ? new PageModel(page) : new PageModel()
            };

            return(notificationTemplateService.ParseNotification(notificationTemplate, model).Body);
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Load setting
        /// </summary>
        /// <returns></returns>
        public virtual T LoadSetting <T>()
        {
            var settingService = HostContainer.GetInstance <IEzSiteSettingService>();
            var settingString  = settingService.GetSetting <string>(GetSetup().Name);

            if (string.IsNullOrEmpty(settingString))
            {
                var setting = GetSetup().DefaultValue;
                settingString = SerializeUtilities.Serialize(setting);
                settingService.InsertSetting(new SiteSetting
                {
                    Name        = GetSetup().Name,
                    Description = GetSetup().Description,
                    Value       = settingString,
                    SettingType = GetSetup().SettingType
                });
                return(setting);
            }

            return(SerializeUtilities.Deserialize <T>(settingString));
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Get toolbar for current user
        /// </summary>
        /// <returns></returns>
        public ToolbarRenderModel GetCurrentUserToolbar()
        {
            if (WorkContext.CurrentUser != null)
            {
                var toolbars =
                    _userGroupService.Fetch(g => WorkContext.CurrentUser.GroupIds.Contains(g.Id) && g.ToolbarId.HasValue)
                    .Select(g => g.Toolbar);

                var basicTools = new List <string>();
                var pageTools  = new List <string>();

                if (toolbars.Any())
                {
                    foreach (var toolbar in toolbars)
                    {
                        var basic = SerializeUtilities.Deserialize <List <string> >(toolbar.BasicToolbar);
                        basicTools.AddRange(basic ?? new List <string>());

                        var page = SerializeUtilities.Deserialize <List <string> >(toolbar.PageToolbar);
                        pageTools.AddRange(page ?? new List <string>());
                    }

                    return(new ToolbarRenderModel
                    {
                        BasicTools = basicTools.Distinct().ToList(),
                        PageTools = pageTools.Distinct().ToList()
                    });
                }
            }

            var defaultToolbar = FetchFirst(t => t.IsDefault);

            if (defaultToolbar != null)
            {
                return(new ToolbarRenderModel(defaultToolbar));
            }

            return(new ToolbarRenderModel());
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Add contact search to group
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ResponseModel AddToGroup(AddToGroupModel model)
        {
            var contactGroupManageModel = new ContactGroupManageModel();

            var contactSearchModel  = SerializeUtilities.Deserialize <ContactSearchModel>(model.ContactSearchModel);
            var contactSearchModels = new List <ContactSearchModel>();

            switch (model.AddToGroupType)
            {
            case ContactGroupEnums.AddToGroupType.New:
                contactSearchModels.Add(contactSearchModel);

                contactGroupManageModel.Name    = model.Name;
                contactGroupManageModel.Queries = SerializeUtilities.Serialize(contactSearchModels);
                break;

            case ContactGroupEnums.AddToGroupType.Existing:
                var contactGroup = GetById(model.Id);
                if (contactGroup != null)
                {
                    contactSearchModels =
                        SerializeUtilities.Deserialize <List <ContactSearchModel> >(contactGroup.Queries);
                    contactSearchModels.Add(contactSearchModel);

                    contactGroupManageModel.Id      = contactGroup.Id;
                    contactGroupManageModel.Name    = contactGroup.Name;
                    contactGroupManageModel.Queries = SerializeUtilities.Serialize(contactSearchModels);
                    contactGroupManageModel.Active  = contactGroup.Active;
                }
                break;
            }

            var response = SaveContactGroup(contactGroupManageModel);

            return(response.SetMessage(response.Success
                ? T("ContactGroup_Message_AddToGroupSuccessfully")
                : T("ContactGroup_Message_AddToGroupFailure")));
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Initialize default settings
        /// </summary>
        public void Initialize(DbContext ezContext)
        {
            var context = ezContext as EzCMSEntities;

            if (context != null)
            {
                if (!context.FormTabs.Any())
                {
                    var now = DateTime.UtcNow;

                    #region Save Templates

                    var embeddedResources = DataInitializeHelper.GetAllResourcesInFolder("FormBuilder.Components",
                                                                                         DataSetupResourceType.Others);

                    foreach (var embeddedResource in embeddedResources)
                    {
                        var formComponentTemplate = new FormComponentTemplate
                        {
                            Name    = Path.GetFileNameWithoutExtension(embeddedResource.Name),
                            Content = embeddedResource.Content
                        };
                        context.FormComponentTemplates.AddEntities(formComponentTemplate);
                    }
                    context.SaveChanges();

                    #endregion

                    #region Save Tabs

                    var setup = DataInitializeHelper.GetResourceContent("FormBuilder.Tabs.json", DataSetupResourceType.Others);
                    var tabs  = SerializeUtilities.Deserialize <List <FormTabModel> >(setup);

                    var tabOrder = 0;
                    foreach (var item in tabs)
                    {
                        tabOrder += 10;
                        var tab = new FormTab
                        {
                            Name        = item.title,
                            RecordOrder = tabOrder,
                            Created     = now,
                            CreatedBy   = FrameworkConstants.DefaultMigrationAccount
                        };

                        var componentOrder = 0;
                        foreach (var data in item.data)
                        {
                            // Get templates for component
                            var formComponentTemplate = context.FormComponentTemplates.First(t => t.Name.Equals(data.template));

                            componentOrder += 10;
                            var component = new FormComponent
                            {
                                FormTab = tab,
                                FormComponentTemplate = formComponentTemplate,
                                Name        = data.title,
                                RecordOrder = componentOrder,
                                Created     = now,
                                CreatedBy   = FrameworkConstants.DefaultMigrationAccount
                            };

                            if (data.fields != null && data.fields.Keys.Any())
                            {
                                var fieldOrder = 0;
                                foreach (var field in data.fields)
                                {
                                    fieldOrder += 10;
                                    var formField = new FormComponentField
                                    {
                                        FormComponent = component,
                                        Name          = field.Key,
                                        Attributes    = SerializeUtilities.Serialize(field.Value),
                                        RecordOrder   = fieldOrder,
                                        Created       = now,
                                        CreatedBy     = FrameworkConstants.DefaultMigrationAccount
                                    };

                                    context.FormComponentFields.AddEntities(formField);
                                }
                            }
                            else
                            {
                                context.FormComponents.AddEntities(component);
                            }
                        }
                    }

                    #endregion

                    #region Save Default Form components

                    var componentsSetup       = DataInitializeHelper.GetResourceContent("FormBuilder.DefaultFormComponents.json", DataSetupResourceType.Others);
                    var defaultFormComponents = SerializeUtilities.Deserialize <List <FormData> >(componentsSetup);

                    var defaultComponentOrder = 0;
                    foreach (var data in defaultFormComponents)
                    {
                        defaultComponentOrder += 10;

                        // Get template for component
                        var formComponentTemplate = context.FormComponentTemplates.First(t => t.Name.Equals(data.template));

                        var component = new FormDefaultComponent
                        {
                            FormComponentTemplate = formComponentTemplate,
                            Name        = data.title,
                            RecordOrder = defaultComponentOrder,
                            Created     = now,
                            CreatedBy   = FrameworkConstants.DefaultMigrationAccount
                        };

                        if (data.fields != null && data.fields.Keys.Any())
                        {
                            var fieldOrder = 0;
                            foreach (var field in data.fields)
                            {
                                fieldOrder += 10;
                                var formField = new FormDefaultComponentField
                                {
                                    FormDefaultComponent = component,
                                    Name        = field.Key,
                                    Attributes  = SerializeUtilities.Serialize(field.Value),
                                    RecordOrder = fieldOrder,
                                    Created     = now,
                                    CreatedBy   = FrameworkConstants.DefaultMigrationAccount
                                };

                                context.FormDefaultComponentFields.AddEntities(formField);
                            }
                        }
                        else
                        {
                            context.FormDefaultComponents.AddEntities(component);
                        }
                    }
                    #endregion

                    context.SaveChanges();
                }
            }
        }