Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
SlavaTT committed Nov 26, 2017
0 parents commit 85a8f69
Show file tree
Hide file tree
Showing 78 changed files with 4,886 additions and 0 deletions.
22 changes: 22 additions & 0 deletions RifleRange.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RifleRange", "RifleRange\RifleRange.csproj", "{0F3C5A9F-B8D9-4532-B35E-1EEBC601D4C0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{0F3C5A9F-B8D9-4532-B35E-1EEBC601D4C0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0F3C5A9F-B8D9-4532-B35E-1EEBC601D4C0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0F3C5A9F-B8D9-4532-B35E-1EEBC601D4C0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0F3C5A9F-B8D9-4532-B35E-1EEBC601D4C0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
21 changes: 21 additions & 0 deletions RifleRange/App_Start/BaseController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using RifleRange.Api;
using System.Web.Http;

namespace RifleRange.Controllers
{
public class BaseController : ApiController
{
protected ModelFactory TheFactory;

public BaseController()
{
TheFactory = new ModelFactory();
}
[HttpGet]
public IHttpActionResult CurrentTime()
{
return Ok(DateTime.Now.ToString());
}
}
}
43 changes: 43 additions & 0 deletions RifleRange/App_Start/ModelFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using RifleRange.DAL;
using RifleRange.Api.Models;
using System.Web.Http.Routing;
using System.Net.Http;
using System.Collections.Generic;

namespace RifleRange.Api
{
public class ModelFactory
{
public ForumThread Create(rrForumThread Thread)
{
ForumThread Model = new ForumThread(Thread);
// Model.URL = UrlHelper.Link("Forum", new { id = Thread.ThreadId.ToString() });

return Model;
}
public ForumThread[] Create(LinkedList<rrForumThread> Threads)
{
ForumThread[] Result = null;

if (Threads != null)
{
Result = new ForumThread[Threads.Count];

int i = 0;

LinkedListNode<rrForumThread> Node = Threads.First;

while (Node != null)
{
Result[i] = Create(Node.Value);

Node = Node.Next;
i++;
}

}

return Result;
}
}
}
24 changes: 24 additions & 0 deletions RifleRange/App_Start/RouteConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Routing;

namespace RifleRange
{
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
}
24 changes: 24 additions & 0 deletions RifleRange/App_Start/WebAPIConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Http;

namespace RifleRange
{
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
// TODO: Add any additional configuration code.

// Web API routes
config.MapHttpAttributeRoutes();

config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
}
}
38 changes: 38 additions & 0 deletions RifleRange/Content/css/site.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
body {
padding-top: 50px;
padding-bottom: 20px;
}

/* Wrapping element */
/* Set some basic padding to keep content from hitting the edges */
.body-content {
padding-left: 15px;
padding-right: 15px;
}

/* Set widths on the form inputs since otherwise they're 100% wide */
input,
select,
textarea {
max-width: 350px;
}

/* Carousel */
.carousel-caption p {
font-size: 20px;
line-height: 1.4;
}

/* Make .svg files in the carousel display properly in older browsers */
.carousel-inner .item img[src$=".svg"]
{
width: 100%;
}

/* Hide/rearrange for smaller screens */
@media screen and (max-width: 767px) {
/* Hide captions */
.carousel-caption {
display: none
}
}
Binary file added RifleRange/Content/images/16b69d2240ed.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added RifleRange/Content/images/20150520_094823.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added RifleRange/Content/images/20151015_143951.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added RifleRange/Content/images/20161127_093020.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added RifleRange/Content/images/20161127_093351.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added RifleRange/Content/images/20161127_093359.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added RifleRange/Content/images/20161127_121354.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added RifleRange/Content/images/20161127_121712.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added RifleRange/Content/images/20161127_121728.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added RifleRange/Content/images/20161127_121749.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added RifleRange/Content/images/481ad82be7dd.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added RifleRange/Content/images/P1040504.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added RifleRange/Content/images/P1040508.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added RifleRange/Content/images/P1040509.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added RifleRange/Content/images/P1040512.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added RifleRange/Content/images/P1040513.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added RifleRange/Content/images/P1050330.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added RifleRange/Content/images/P1050331.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions RifleRange/Content/js/Helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
$.urlParam = function(name){
var results = new RegExp('[\?&]' + name + '=([^]*)').exec(window.location.href);
if (results==null){
return null;
}
else{
return results[1] || 0;
}
}
189 changes: 189 additions & 0 deletions RifleRange/Controllers/API/ForumController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Xml;
using System.Text;
using System.Runtime.Serialization.Json;
using System.IO;
using Newtonsoft.Json;
using RifleRange.DAL;
using RifleRange.Api.Models;


namespace RifleRange.Controllers.API
{
public class ForumController : BaseController
{
const int ForumId = 2;

[HttpGet]
public HttpResponseMessage GetForumThread(int Id)
{
HttpResponseMessage Response = null;

try
{
string JSON = "[\r\n " + GetThreadJSON(Id) + " \r\n]";
Response = new HttpResponseMessage()
{
StatusCode = HttpStatusCode.OK,
Content = new StringContent(content: JSON, encoding: UTF8Encoding.Default, mediaType: "application/json"),
};
}
catch (Exception ex)
{
Response = Request.CreateErrorResponse(statusCode: HttpStatusCode.BadRequest, exception: ex);
}
return Response;
}
[Authorize]
[HttpPost]
[Route("api/Forum")]
public IHttpActionResult Reply(ForumThreadReply Reply)
{
IHttpActionResult Response = null;
try
{
if (!ModelState.IsValid)
{
Response = BadRequest(ModelState);
}
else
{
int ForumThreadId = rrForumThreadDB.InsertForumThreadReply(
UserId: Reply.CreatedBy,
ThreadParentId: Reply.ThreadParentId,
Description: Uri.UnescapeDataString(Reply.Description));

string NewUrl = string.Format("api/Forum/{0}", ForumThreadId);
Response = Created(NewUrl, string.Empty);
}
}
catch (Exception ex)
{
Response = BadRequest(ex.Message);
}
return Response;
}
[HttpPut]
public IHttpActionResult Edit(int Id, [FromBody]string Description)
{
IHttpActionResult Response = null;

try
{
LinkedList<rrForumThread> lstThread = rrForumThreadDB.GetForumThread(ForumId: ForumId, ThreadId: Id);
if (lstThread.Count == 0)
Response = NotFound();
else
{
rrForumThread Thread = lstThread.First.Value;

rrForumThreadDB.UpdateForumThread(ForumId: ForumId, ThreadId: Id,
UserId: Thread.CreatedBy, Title: Thread.Title,
Description: Uri.UnescapeDataString(Description),
FileName: Thread.FileName);

Response = Ok();
}
}
catch (Exception ex)
{
Response = BadRequest(ex.Message);
}
return Response;
}
[HttpDelete]
public IHttpActionResult Delete(int Id)
{
IHttpActionResult Response = null;

try
{
LinkedList<rrForumThread> lstThread = rrForumThreadDB.GetForumThread(ForumId: ForumId, ThreadId: Id);
if (lstThread.Count == 0)
Response = NotFound();
else
{
rrForumThread Thread = lstThread.First.Value;

rrForumThreadDB.DeleteForumThread(ForumId: ForumId, ThreadId: Id);

Response = Ok();
}
}
catch (Exception ex)
{
Response = BadRequest(ex.Message);
}
return Response;
}


private string GetThreadJSON(int StartThreadId)
{
LinkedList<rrForumThread> llThreads = rrForumThreadDB.GetForumThread(ForumId: ForumId,
StartThreadId: StartThreadId, IncludeStartThread: true);


return OutputThreadJSON(llThreads, StartThreadId);
}

private string OutputThreadJSON(LinkedList<rrForumThread> ThreadList, int ThreadId)
{
LinkedListNode<rrForumThread> Node = ThreadList.First;

while (Node != null)
{
if (Node.Value.ThreadId == ThreadId) break;

Node = Node.Next;
}
string JsonText = string.Empty;

if (Node != null)
{
ForumThread Thread = new ForumThread(ThreadList, Node);

JsonText = JsonConvert.SerializeObject(Thread, Newtonsoft.Json.Formatting.Indented);
}
return JsonText;
}
private rrForumThread FindThreadById(LinkedList<rrForumThread> ThreadList, int ThreadId)
{
rrForumThread Result = null;

LinkedListNode<rrForumThread> Node = ThreadList.First;

while (Node != null)
{
rrForumThread Thread = Node.Value;
if (Thread.ThreadId == ThreadId)
{
Result = Thread;
break;
}

Node = Node.Next;
}

return Result;
}
private LinkedList<rrForumThread> FindThreadByParentId(LinkedList<rrForumThread> ThreadList,
int ThreadId)
{
LinkedList<rrForumThread> Result = new LinkedList<rrForumThread>();

foreach (rrForumThread Thread in ThreadList)
{
if (Thread.ThreadParentId == ThreadId)
Result.AddLast(Thread);
}

return Result;
}

}
}
Loading

0 comments on commit 85a8f69

Please sign in to comment.