예제 #1
0
 public static Blog ToModel(this ioschools.DB.blog row)
 {
     return(new Blog()
     {
         id = row.id.ToString(),
         pagetitle = row.title,
         title = row.title,
         creator = row.user.ToName(),
         body = row.body,
         ispublic = row.ispublic,
         date = row.created.ToString(Constants.DATEFORMAT_DATEPICKER)
     });
 }
예제 #2
0
        private static string ToStatus(this ioschools.DB.blog row)
        {
            var sb = new StringBuilder();

            if (row.ispublic)
            {
                sb.AppendFormat("<span class='tag_green'>public</span>");
            }
            else
            {
                sb.AppendFormat("<span class='tag_red'>unpublished</span>");
            }

            if (row.emailed)
            {
                sb.AppendFormat("<span class='tag_blue'>emailed</span>");
            }

            return(sb.ToString());
        }
예제 #3
0
        public ActionResult Save(long?id, string title, string photoids, string attachmentids,
                                 string content, Schools?school, bool test = false, bool blog_public = false, bool blog_email = false, bool blog_gallery = false)
        {
            if (test)
            {
                // just send test email
                var viewdata = new ViewDataDictionary
                {
                    { "title", title },
                    { "content", content },
                    { "sender", repository.GetUser(sessionid.Value).ToName() }
                };
                var usr = repository.GetUser(sessionid.Value);
                EmailHelper.SendEmailNow(
                    EmailViewType.CIRCULAR,
                    viewdata,
                    title,
                    usr.email,
                    usr.ToName());
                return(Json("A test email has been sent to your account".ToJsonOKMessage()));
            }

            var blog = new ioschools.DB.blog
            {
                created = DateTime.Now,
                creator = sessionid.Value
            };

            if (id.HasValue)
            {
                blog = repository.GetBlog(id.Value);
            }

            blog.title    = title;
            blog.body     = content;
            blog.ispublic = blog_public;


            if (blog_gallery)
            {
                blog.layoutMethod = (byte)LayoutMethod.GALLERY;
            }
            else
            {
                blog.layoutMethod = (byte)LayoutMethod.SIDE;
            }

            if (!id.HasValue)
            {
                repository.AddBlog(blog);
            }

            try
            {
                repository.Save();

                // update photos
                if (!string.IsNullOrEmpty(photoids))
                {
                    var photos = photoids.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                    repository.UpdateBlogImages(blog.id, photos); // submit
                }


                // update attachments
                if (!string.IsNullOrEmpty(attachmentids))
                {
                    var files = attachmentids.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                    repository.UpdateBlogFiles(blog.id, files); // submit
                }

                // don't send if it's draft
                // check if it has already been sent
                if (blog_email && blog_public && !blog.emailed)
                {
                    // do we have permission
                    if (!auth.perms.HasFlag(Permission.NEWS_BROADCAST))
                    {
                        return(Json("You do not have permission to send circulars".ToJsonFail()));
                    }

                    // update sent
                    blog.emailed = blog_email;
                    repository.Save();

                    var viewdata = new ViewDataDictionary
                    {
                        { "title", title },
                        { "content", content },
                        { "sender", repository.GetUser(sessionid.Value).ToName() }
                    };
                    new Thread(() =>
                    {
                        using (var repo = new Repository())
                        {
                            IQueryable <user> usrs = null;
                            if (school.HasValue)
                            {
                                usrs = repo.GetUsers(null, null, school.Value.ToInt(), null, null, null, null, null, DateTime.Now.Year, null);
                            }

                            if (usrs != null)
                            {
                                foreach (var usr in usrs)
                                {
                                    // don't send to parents whoose children has not been accepted
                                    if (usr.usergroup == (int)UserGroup.GUARDIAN)
                                    {
                                        if (!usr.students_guardians1.Select(x => x.user.classes_students_allocateds).Any())
                                        {
                                            continue;
                                        }
                                    }

                                    if (!string.IsNullOrEmpty(usr.email))
                                    {
                                        EmailHelper.SendEmail(
                                            EmailViewType.CIRCULAR,
                                            viewdata,
                                            title,
                                            usr.email,
                                            usr.ToName());
                                    }
                                }
                            }
                        }
                    }).Start();
                }
            }
            catch (Exception ex)
            {
                Syslog.Write(ex);
                return(Json("Unable to create entry.".ToJsonFail()));
            }

            return(Json("Entry updated successfully".ToJsonOKMessage()));
        }