private static void SeedKnifes(SharpStoreContext context) { IList <Knife> knives = new List <Knife>(); knives.Add(new Knife() { Name = "Knive Sharp One", Price = 267.55m, ImageURL = "images/sharp3.png" }); knives.Add(new Knife() { Name = "Knive Sharp Second", Price = 467.99m, ImageURL = "images/sharp4.jpg" }); knives.Add(new Knife() { Name = "Other Sharp", Price = 99m, ImageURL = "images/sharp5.jpg" }); knives.Add(new Knife() { Name = "Some Knive", Price = 111.87m, ImageURL = "images/knife-sharp1.jpg" }); knives.Add(new Knife() { Name = "Any Knive", Price = 900.99m, ImageURL = "images/knife-sharp2.jpg" }); foreach (Knife knive in knives) { context.Knives.AddOrUpdate(k => k.Name, knive); } context.SaveChanges(); System.Console.WriteLine("Knives was added successfuly!"); }
private static void SeedUsers(SharpStoreContext context) { IList <User> users = new List <User>(); users.Add(new User() { Username = "******", Email = "*****@*****.**" }); users.Add(new User() { Username = "******", Email = "*****@*****.**" }); users.Add(new User() { Username = "******", Email = "*****@*****.**" }); users.Add(new User() { Username = "******", Email = "*****@*****.**" }); users.Add(new User() { Username = "******", Email = "*****@*****.**" }); foreach (User user in users) { context.Users.AddOrUpdate(u => u.Username, user); } context.SaveChanges(); System.Console.WriteLine("Users was added successfuly!"); }
public static void HandleContactsPost(string incomingRequestString) { PostParameters = DecodeParams(incomingRequestString); var context = new SharpStoreContext(); Message message = new Message() { Sender = PostParameters["email"], Subject = PostParameters["subject"], Content = PostParameters["content"] }; context.Messages.Add(message); context.SaveChanges(); }
static void Main() { //create database SharpStoreDB and seed data SharpStoreContext context = Data.Context; context.Database.Initialize(true); SeedUsers(context); SeedKnifes(context); //config and run server var routes = RoutesConfig.UseRoutes(); HttpServer httpServer = new HttpServer(8081, routes); httpServer.Listen(); }
private static void UploadMessageInDB(HttpRequest request, SharpStoreContext context) { string requestContent = WebUtility.UrlDecode(request.Content); string[] parameters = requestContent.Split('&'); Dictionary <string, string> nameValuePair = new Dictionary <string, string>(); foreach (var parameter in parameters) { string[] parameterInfo = parameter.Split('='); nameValuePair.Add(parameterInfo[0], parameterInfo[1]); } Message message = new Message() { Sender = nameValuePair["emailAddress"], Subject = nameValuePair["subject"], FullMessage = nameValuePair["message"] }; context.Messages.Add(message); context.SaveChanges(); }
public static string BuildKnivesPage(PageBuilderFactory factory, CookieCollection cookies, string where = null) { string pageTop = factory.BuildThemedPage(cookies, "products-top.html"); StringBuilder pageBuilder = new StringBuilder(); pageBuilder.Append(pageTop); var context = new SharpStoreContext(); List <Knife> knives = new List <Knife>(); if (string.IsNullOrEmpty(where)) { knives = context.Knives.ToList(); } else { knives = context.Knives.Where(k => k.Name.Contains(where)).ToList(); } foreach (var knife in knives) { string base64 = Convert.ToBase64String(File.ReadAllBytes(knife.ImageUrl)); pageBuilder.AppendLine($@"<div class=""card col-md-4""> <img class=""img-thumbnail"" src=""data:image;base64,{base64}"" width=""300"" height=""150"" alt=""{knife.Name}""> <div class=""card-block""> <h4 class=""card-title"">{knife.Name}</h4> <p class=""card-text"">{knife.Price}</p> <form method=""POST""> <input type=""submit"" class=""btn btn-primary"" value=""Buy Now""> </form> </div> </div>"); } string pageBottom = File.ReadAllText(@"../../content/products-bottom.html"); pageBuilder.Append(pageBottom); return(pageBuilder.ToString()); }
public AdminController() { this.context = new SharpStoreContext(); this.signInManager = new SignInManager(this.context); }
static void Main(string[] args) { SharpStoreContext context = new SharpStoreContext(); var routes = new List <Route>() { new Route() { Name = "Home Directory", Method = SimpleHttpServer.Enums.RequestMethod.GET, UrlRegex = "^/home$", Callable = (request) => { return(new HttpResponse() { StatusCode = SimpleHttpServer.Enums.ResponseStatusCode.Ok, ContentAsUTF8 = File.ReadAllText("../../content/home.html") }); } }, new Route() { Name = "Carousel CSS", Method = SimpleHttpServer.Enums.RequestMethod.GET, UrlRegex = "^/content/css/carousel.css$", Callable = (request) => { var response = new HttpResponse() { StatusCode = SimpleHttpServer.Enums.ResponseStatusCode.Ok, ContentAsUTF8 = File.ReadAllText("../../content/css/carousel.css") }; response.Header.ContentType = "text/css"; return(response); } }, new Route() { Name = "Bootstrap JS", Method = SimpleHttpServer.Enums.RequestMethod.GET, UrlRegex = "^/bootstrap/js/bootstrap.min.js$", Callable = (request) => { var response = new HttpResponse() { StatusCode = SimpleHttpServer.Enums.ResponseStatusCode.Ok, ContentAsUTF8 = File.ReadAllText("../../content/bootstrap/js/bootstrap.min.js") }; response.Header.ContentType = "application/x-javascript"; return(response); } }, new Route() { Name = "Bootstrap CSS", Method = SimpleHttpServer.Enums.RequestMethod.GET, UrlRegex = "^/bootstrap/css/bootstrap.min.css$", Callable = (request) => { var response = new HttpResponse() { StatusCode = SimpleHttpServer.Enums.ResponseStatusCode.Ok, ContentAsUTF8 = File.ReadAllText("../../content/bootstrap/css/bootstrap.min.css") }; response.Header.ContentType = "text/css"; return(response); } }, new Route() { Name = "About Directory", Method = SimpleHttpServer.Enums.RequestMethod.GET, UrlRegex = "^/about$", Callable = (request) => { return(new HttpResponse() { StatusCode = SimpleHttpServer.Enums.ResponseStatusCode.Ok, ContentAsUTF8 = File.ReadAllText("../../content/about.html") }); } }, new Route() { Name = "About Pictures", Method = SimpleHttpServer.Enums.RequestMethod.GET, UrlRegex = "^/images/.+$", Callable = (request) => { var nameOfFile = request.Url.Substring(request.Url.LastIndexOf('/') + 1); return(new HttpResponse() { StatusCode = SimpleHttpServer.Enums.ResponseStatusCode.Ok, Content = File.ReadAllBytes($"../../content/images/{nameOfFile}") }); } }, new Route() { Name = "Products Directory", Method = SimpleHttpServer.Enums.RequestMethod.GET, UrlRegex = "^/products$", Callable = (request) => { var knives = context.Knives.ToList(); var products = GenerateProducts(knives); return(new HttpResponse() { StatusCode = SimpleHttpServer.Enums.ResponseStatusCode.Ok, ContentAsUTF8 = products }); } }, new Route() { Name = "Products Directory", Method = SimpleHttpServer.Enums.RequestMethod.POST, UrlRegex = "^/products$", Callable = (request) => { string filter = request.Content.Split('=')[1]; var knives = context.Knives.Where(k => k.Name.Contains(filter)).ToList(); var products = GenerateProducts(knives); return(new HttpResponse() { StatusCode = SimpleHttpServer.Enums.ResponseStatusCode.Ok, ContentAsUTF8 = products }); } }, new Route() { Name = "Contants Directory", Method = SimpleHttpServer.Enums.RequestMethod.GET, UrlRegex = "^/contacts$", Callable = (request) => { return(new HttpResponse() { StatusCode = SimpleHttpServer.Enums.ResponseStatusCode.Ok, ContentAsUTF8 = File.ReadAllText("../../content/contact.html") }); } }, new Route() { Name = "Contants Directory", Method = SimpleHttpServer.Enums.RequestMethod.POST, UrlRegex = "^/contacts$", Callable = (request) => { UploadMessageInDB(request, context); return(new HttpResponse() { StatusCode = SimpleHttpServer.Enums.ResponseStatusCode.Ok, ContentAsUTF8 = File.ReadAllText("../../content/contact.html") }); } } }; HttpServer httpServer = new HttpServer(8081, routes); httpServer.Listen(); }
public Service(SharpStoreContext context) { this.context = context; }
public ProductService() { this.context = new SharpStoreContext(); }
public MessagesService(SharpStoreContext context) : base(context) { }
public static void Main() { ISharpStoreContext context = new SharpStoreContext(); IHtmlProvider htmlProvider = new HtmlProvider(context); ICustomServiceProvider serviceProvider = new ServiceProvider(context); var routes = new List <Route>() { new Route() { Name = "Html pages", Method = RequestMethod.GET, UrlRegex = "^\\/.+\\.html.*", Callable = (request) => { string pageName = GetPageNameByUrl(request); IHtml html = htmlProvider.GetHtmlPage(pageName); var response = new HttpResponse() { StatusCode = ResponseStatusCode.Ok, ContentAsUtf8 = html?.Print(request.Url) }; return(response); } }, new Route() { Name = "Html pages Post", Method = RequestMethod.POST, UrlRegex = "^\\/.+\\.html$", Callable = (request) => { string pageName = GetPageNameByUrl(request); IHtml html = htmlProvider.GetHtmlPage(pageName); serviceProvider.ExecuteRequest(request); var response = new HttpResponse() { StatusCode = ResponseStatusCode.Ok, ContentAsUtf8 = html.Print(request.Url) }; return(response); } }, new Route() { Name = "Carousel CSS", Method = RequestMethod.GET, UrlRegex = "^/content/css/carousel.css$", Callable = (request) => { var response = new HttpResponse { StatusCode = ResponseStatusCode.Ok, ContentAsUtf8 = File.ReadAllText("../../content/css/carousel.css"), Header = { ContentType = "text/css" } }; return(response); } }, new Route() { Name = "Products CSS", Method = RequestMethod.GET, UrlRegex = "^/content/productsTest.css$", Callable = (request) => { var response = new HttpResponse { StatusCode = ResponseStatusCode.Ok, ContentAsUtf8 = File.ReadAllText("../../content/products.css"), Header = { ContentType = "text/css" } }; return(response); } }, new Route() { Name = "Bootstrap JS", Method = RequestMethod.GET, UrlRegex = "^/bootstrap/js/bootstrap.min.js$", Callable = (request) => new HttpResponse { StatusCode = ResponseStatusCode.Ok, ContentAsUtf8 = File.ReadAllText("../../content/bootstrap/js/bootstrap.min.js"), Header = { ContentType = "application/x-javascript" } } }, new Route() { Name = "Bootstrap CSS", Method = RequestMethod.GET, UrlRegex = "^/bootstrap/css/bootstrap.min.css$", Callable = request => new HttpResponse() { StatusCode = ResponseStatusCode.Ok, ContentAsUtf8 = File.ReadAllText("../../content/bootstrap/css/bootstrap.min.css"), Header = { ContentType = "text/css" } } } }; HttpServer server = new HttpServer(8081, routes); server.Listen(); }
static void Main(string[] args) { SharpStoreContext context = new SharpStoreContext(); var routes = new List <Route>() { new Route() { Name = "Change Theme", Method = SimpleHttpServer.Enums.RequestMethod.GET, UrlRegex = "^/.+?\\?theme=.+$", Callable = (request) => { var indexOfQuestion = request.Url.IndexOf('?'); var htmlName = request.Url.Substring(1, indexOfQuestion - 1); var lastIndexOfEquals = request.Url.LastIndexOf('='); var theme = request.Url.Substring(lastIndexOfEquals + 1); var response = new HttpResponse() { StatusCode = SimpleHttpServer.Enums.ResponseStatusCode.Ok, ContentAsUTF8 = File.ReadAllText($"../../content/{htmlName}.html") }; response.Header.Cookies.Add(new Cookie("theme", theme)); return(response); } }, new Route() { Name = "Theme CSS", Method = SimpleHttpServer.Enums.RequestMethod.GET, UrlRegex = @"^/content/css/navbar-.+", Callable = (request) => { var theme = GetTheme(request); var response = new HttpResponse() { StatusCode = SimpleHttpServer.Enums.ResponseStatusCode.Ok, ContentAsUTF8 = File.ReadAllText($"../../content/css/navbar-{theme}.css") }; response.Header.ContentType = "text/css"; return(response); } }, new Route() { Name = "Home Directory", Method = SimpleHttpServer.Enums.RequestMethod.GET, UrlRegex = "^/home$", Callable = (request) => { string theme = GetTheme(request); return(new HttpResponse() { StatusCode = SimpleHttpServer.Enums.ResponseStatusCode.Ok, ContentAsUTF8 = File.ReadAllText("../../content/home.html").Replace("{0}", theme) }); } }, new Route() { Name = "About Directory", Method = SimpleHttpServer.Enums.RequestMethod.GET, UrlRegex = "^/about$", Callable = (request) => { string theme = GetTheme(request); return(new HttpResponse() { StatusCode = SimpleHttpServer.Enums.ResponseStatusCode.Ok, ContentAsUTF8 = File.ReadAllText("../../content/about.html").Replace("{0}", theme) }); } }, new Route() { Name = "Product Directory", Method = SimpleHttpServer.Enums.RequestMethod.GET, UrlRegex = "^/products$", Callable = (request) => { string theme = GetTheme(request); var knives = context.Knives.ToList(); string porductsFinal = GenerateKnives(knives); return(new HttpResponse() { StatusCode = SimpleHttpServer.Enums.ResponseStatusCode.Ok, ContentAsUTF8 = porductsFinal.Replace("{0}", theme) }); } }, new Route() { Name = "Product Directory", Method = SimpleHttpServer.Enums.RequestMethod.POST, UrlRegex = "^/products$", Callable = (request) => { string theme = GetTheme(request); string searchFilter = request.Content.Split('=')[1]; var knives = context.Knives.Where(k => k.Name.Contains(searchFilter)).ToList(); string porductsFinal = GenerateKnives(knives); return(new HttpResponse() { StatusCode = SimpleHttpServer.Enums.ResponseStatusCode.Ok, ContentAsUTF8 = porductsFinal.Replace("{0}", theme) }); } }, new Route() { Name = "Contact Directory", Method = SimpleHttpServer.Enums.RequestMethod.GET, UrlRegex = "^/contacts$", Callable = (request) => { string theme = GetTheme(request); return(new HttpResponse() { StatusCode = SimpleHttpServer.Enums.ResponseStatusCode.Ok, ContentAsUTF8 = File.ReadAllText("../../content/contacts.html").Replace("{0}", theme) }); } }, new Route() { Name = "Contact Directory", Method = SimpleHttpServer.Enums.RequestMethod.POST, UrlRegex = "^/contacts$", Callable = (request) => { UpploadMessageToDB(request, context); return(new HttpResponse() { StatusCode = SimpleHttpServer.Enums.ResponseStatusCode.Ok, ContentAsUTF8 = File.ReadAllText("../../content/contacts.html") }); } }, new Route() { Name = "Images", Method = SimpleHttpServer.Enums.RequestMethod.GET, UrlRegex = @"^/images/.+", Callable = (request) => { var nameOfFile = request.Url.Substring(request.Url.LastIndexOf('/') + 1); var response = new HttpResponse() { StatusCode = SimpleHttpServer.Enums.ResponseStatusCode.Ok, Content = File.ReadAllBytes($"../../content/images/{nameOfFile}") }; response.Header.ContentType = "images/*"; response.Header.ContentLength = response.Content.Length.ToString(); return(response); } }, new Route() { Name = "Carousel CSS", Method = SimpleHttpServer.Enums.RequestMethod.GET, UrlRegex = "^/content/css/carousel.css$", Callable = (request) => { var response = new HttpResponse() { StatusCode = SimpleHttpServer.Enums.ResponseStatusCode.Ok, ContentAsUTF8 = File.ReadAllText("../../content/css/carousel.css") }; response.Header.ContentType = "text/css"; return(response); } }, new Route() { Name = "Bootstrap JS", Method = SimpleHttpServer.Enums.RequestMethod.GET, UrlRegex = "^/bootstrap/js/bootstrap.min.js$", Callable = (request) => { var response = new HttpResponse() { StatusCode = SimpleHttpServer.Enums.ResponseStatusCode.Ok, ContentAsUTF8 = File.ReadAllText("../../content/bootstrap/js/bootstrap.min.js") }; response.Header.ContentType = "application/x-javascript"; return(response); } }, new Route() { Name = "Bootstrap CSS", Method = SimpleHttpServer.Enums.RequestMethod.GET, UrlRegex = "^/bootstrap/css/bootstrap.min.css$", Callable = (request) => { var response = new HttpResponse() { StatusCode = SimpleHttpServer.Enums.ResponseStatusCode.Ok, ContentAsUTF8 = File.ReadAllText("../../content/bootstrap/css/bootstrap.min.css") }; response.Header.ContentType = "text/css"; return(response); } } }; SimpleHttpServer.HttpServer httpServer = new HttpServer(8081, routes); httpServer.Listen(); }
public MessagesService() { this.context = Data.Context; }
public PurchaseService(SharpStoreContext context) : base(context) { }
public KnivesService() { this.context = Data.Data.Context; }
public BuyService(SharpStoreContext context) : base(context) { }
public KnifeService(SharpStoreContext context) : base(context) { }
public HomeController() { this.context = new SharpStoreContext(); }
public KnivesService() { this.context = new SharpStoreContext(); }
public ProductsService(SharpStoreContext context) : base(context) { }
public LoginService(SharpStoreContext context) : base(context) { }