yavsc/web/Controllers/HomeController.cs
Paul Schneider 9494d6f353 Hallo now edits my images,
and each post can display a dedicated photo.

* NpgsqlBlogProvider.cs: implements a blog post photo storage

* BlogsController.cs: implements a method to update the photo url

* style.css: yastyle

* AdminController.cs: refactoring the notification:
Introduces a static `Notice` method, server side, to populate an array
in `ViewData`, used in the paster page.

* BlogsController.cs: Controls the photo update

* YavscHelpers.cs:
* yavsc.circles.js:
* HomeController.cs:
* GoogleController.cs: notification refactoring

* App.master: - notification refactoring
- html structure in the `nav`

* hallo.js: event 'hallomodified' now also occurs at image
  modifications

* to-markdown.js: ?Fixes? html images alt text and title to Markdown

* yavsc.js: implements the photo in database

* Edit.aspx: A nicer bill edition, with a photo

* UserPost.aspx: Displays the photo

* UserPosts.aspx: Fixes the new usage of `ResultPages`

* Web.config: totem custo

* instdbws.sql: adds a `photo` field in the `blog` table

* BlogEntry.cs: defines the photo in the model

* BlogManager.cs: a new method to set the photo on a blog post.

* BlogProvider.cs: the blog provider now also gives some photo

* LocalizedText.fr.Designer.cs: Reordering the french localisation
  resource

* LocalizedText.fr.resx: Reorders the french localisation resource
2015-10-08 12:43:04 +02:00

126 lines
3.1 KiB
C#

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Net.Mail;
using System.Web;
using System.Web.Configuration;
using System.Reflection;
using System.Resources;
using Yavsc.Model;
using Npgsql.Web;
using Npgsql.Web.Blog;
using Yavsc.Helpers;
using Yavsc;
using System.Web.Mvc;
namespace Yavsc.Controllers
{
/// <summary>
/// Home controller.
/// </summary>
public class HomeController : Controller
{
// Site name
private static string name = null;
/// <summary>
/// Gets or sets the site name.
/// </summary>
/// <value>The name.</value>
[Obsolete("Use YavscHelpers.SiteName insteed.")]
public static string Name {
get {
if (name == null)
name = WebConfigurationManager.AppSettings ["Name"];
return name;
}
}
/// <summary>
/// Lists the referenced assemblies.
/// </summary>
/// <returns>The info.</returns>
public ActionResult AssemblyInfo()
{
Assembly[] aslist = {
GetType ().Assembly,
typeof(ITCPNpgsqlProvider).Assembly,
typeof(NpgsqlMembershipProvider).Assembly,
typeof(NpgsqlContentProvider).Assembly,
typeof(NpgsqlBlogProvider).Assembly
};
List <AssemblyName> asnlist = new List<AssemblyName> ();
foreach (Assembly asse in aslist) {
foreach (AssemblyName an in asse.GetReferencedAssemblies ()) {
if (asnlist.All(x=> string.Compare(x.Name,an.Name)!=0))
asnlist.Add (an);
}
}
asnlist.Sort (delegate(AssemblyName x, AssemblyName y) {
return string.Compare (x.Name, y.Name);
});
return View (asnlist.ToArray()) ;
}
private static string owneremail = null;
/// <summary>
/// Gets or sets the owner email.
/// </summary>
/// <value>The owner email.</value>
public static string OwnerEmail {
get {
if (owneremail == null)
owneremail = WebConfigurationManager.AppSettings.Get ("OwnerEMail");
return owneremail;
}
set {
owneremail = value;
}
}
/// <summary>
/// Index this instance.
/// </summary>
public ActionResult Index ()
{
return View ();
}
/// <summary>
/// Contact the specified email, reason and body.
/// </summary>
/// <param name="email">Email.</param>
/// <param name="reason">Reason.</param>
/// <param name="body">Body.</param>
public ActionResult Contact (string email, string reason, string body)
{
if (email==null)
ModelState.AddModelError("email","Enter your email");
if (reason==null)
ModelState.AddModelError("reason","Please, fill in a reason");
if (body==null)
ModelState.AddModelError("body","Please, fill in a body");
if (!ModelState.IsValid)
return View ();
// requires valid owner and admin email?
if (OwnerEmail == null)
throw new Exception ("No site owner!");
using (System.Net.Mail.MailMessage msg = new MailMessage(email,OwnerEmail,"[Contact] "+reason,body))
{
msg.CC.Add(new MailAddress(YavscHelpers.Admail));
using (System.Net.Mail.SmtpClient sc = new SmtpClient())
{
sc.Send (msg);
YavscHelpers.Notice(ViewData, LocalizedText.Message_sent);
return View (new { email=email, reason="", body="" });
}
}
}
}
}