Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Karan Desai committed Feb 3, 2020
1 parent 76ec485 commit 36d718a
Show file tree
Hide file tree
Showing 55 changed files with 39,804 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Appreciation.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
</ItemGroup>



</Project>
25 changes: 25 additions & 0 deletions Appreciation.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29403.142
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Appreciation", "Appreciation.csproj", "{3A4B7DC4-C51F-4327-BF44-FF5A2016E437}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{3A4B7DC4-C51F-4327-BF44-FF5A2016E437}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3A4B7DC4-C51F-4327-BF44-FF5A2016E437}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3A4B7DC4-C51F-4327-BF44-FF5A2016E437}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3A4B7DC4-C51F-4327-BF44-FF5A2016E437}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {F538F6B0-43DC-43F0-AF86-00E147685140}
EndGlobalSection
EndGlobal
58 changes: 58 additions & 0 deletions Controllers/AppreciationListController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Appreciation.Models;
using Microsoft.AspNetCore.Hosting;
using System.IO;
using System.Text;
using Newtonsoft.Json;

namespace Appreciation.Controllers
{
public class AppreciationListController : Controller
{
private readonly ILogger<HomeController> _logger;
public IHostingEnvironment _env;

public AppreciationListController(ILogger<HomeController> logger, IHostingEnvironment env)
{
_logger = logger;
_env = env;
}

[HttpGet]
public IActionResult Index()
{
string tempPath = System.IO.Path.Combine(_env.WebRootPath, "abcd.txt");
if (!System.IO.File.Exists(tempPath))
{
return View("Index");

}
string data = System.IO.File.ReadAllText(tempPath);
var entryList = new List<MessageViewModel>();
var eachEntry= data.Split(",{{*}}", StringSplitOptions.RemoveEmptyEntries);
foreach(var entry in eachEntry)
{
entryList.Add(JsonConvert.DeserializeObject<MessageViewModel>(entry));

}

return View("Index",entryList);
}





[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
}
}
62 changes: 62 additions & 0 deletions Controllers/HomeController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Appreciation.Models;
using Microsoft.AspNetCore.Hosting;
using System.IO;
using System.Text;
using Newtonsoft.Json;

namespace Appreciation.Controllers
{
public class HomeController : Controller
{
private readonly ILogger<HomeController> _logger;
public IHostingEnvironment _env;

public HomeController(ILogger<HomeController> logger, IHostingEnvironment env)
{
_logger = logger;
_env = env;
}

[HttpGet]
public IActionResult Index()
{
MessageViewModel message = new MessageViewModel();
return View();
}



[HttpPost]
[ValidateAntiForgeryToken]
public IActionResult Index([Bind("AppreciateToName,AppreciationMessage,NameOfPoster,ShowAppreciatorName")]MessageViewModel message)
{
string tempPath = System.IO.Path.Combine(_env.WebRootPath, "abcd.txt");
if (!System.IO.File.Exists(tempPath))
{
System.IO.File.Create(tempPath);

}
message.CreationDateTime = DateTime.UtcNow;
message.Id = Guid.NewGuid().ToString();

//var readAllDataOfFile = System.IO.File.ReadAllBytes(tempPath);
System.IO.File.AppendAllText(tempPath, string.Format("{0},{1}",JsonConvert.SerializeObject(message), "{{*}}"));

return RedirectToAction("Index", "AppreciationList");

}

[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
}
}
11 changes: 11 additions & 0 deletions Models/ErrorViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;

namespace Appreciation.Models
{
public class ErrorViewModel
{
public string RequestId { get; set; }

public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
}
}
32 changes: 32 additions & 0 deletions Models/MessageViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;

namespace Appreciation.Models
{
public class MessageViewModel
{
[Required]
public string Id { get; set; }

[Required]
public string AppreciateToName { get; set; }

[MaxLength(1000)]
[MinLength(15)]
[DataType(DataType.MultilineText)]
[Required]
public string AppreciationMessage { get; set; }

[Required]
public DateTime CreationDateTime { get; set; }



public bool ShowAppreciatorName { get; set; }

public string NameOfPoster { get; set; }
}
}
26 changes: 26 additions & 0 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

namespace Appreciation
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}

public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
}
27 changes: 27 additions & 0 deletions Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:52507",
"sslPort": 44375
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"Appreciation": {
"commandName": "Project",
"launchBrowser": true,
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
57 changes: 57 additions & 0 deletions Startup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace Appreciation
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}

public IConfiguration Configuration { get; }

// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddControllersWithViews();
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();

app.UseRouting();

app.UseAuthorization();

app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
});
}
}
}
31 changes: 31 additions & 0 deletions Views/AppreciationList/Index.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
@{
ViewData["Title"] = "Appreciations";
}
@model List<Appreciation.Models.MessageViewModel>

<h1>@ViewData["Title"]</h1>

@if (Model == null || Model.Count==0)
{
<span>"List is empty"</span>
}
else
{

@foreach (var item in Model)
{
<br/>
<br/>
<span>Hello,</span><span><b>@item.AppreciateToName</b></span><br />
<span>@item.AppreciationMessage</span><br />

if (@item.ShowAppreciatorName)
{
<span>From,</span> <span>@item.NameOfPoster</span><br/>
}

}
}



41 changes: 41 additions & 0 deletions Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
@{
ViewData["Title"] = "Appreciation";
}
@model Appreciation.Models.MessageViewModel

<div class="text-center">
<i>Appreciation is a wonderful thing. It makes what is excellent in others belong to us as well</i>
-<b>Voltaire</b>
</div>

<div class="row">
<div class="col-md-4">
<form asp-action="Index">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<label asp-for=AppreciateToName class="control-label"></label>
<input asp-for=AppreciateToName class="form-control" />
<span asp-validation-for=AppreciateToName class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for=AppreciationMessage class="control-label"></label>
<textarea asp-for=AppreciationMessage class="form-control" id="CreateContentTextArea"></textarea>
<span asp-validation-for=AppreciationMessage class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for=NameOfPoster class="control-label"></label>
<input asp-for=NameOfPoster class="form-control" />
<span asp-validation-for=NameOfPoster class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for=ShowAppreciatorName class="control-label"></label>
<input type="checkbox" asp-for=ShowAppreciatorName class="form-control" id="ShowAppreciatorName" />
<span asp-validation-for=ShowAppreciatorName class="text-danger"></span>

</div>
<div class="form-group">
<input type="submit" value="Submit" class="btn btn-secondary" />
</div>
</form>
</div>
</div>
Loading

0 comments on commit 36d718a

Please sign in to comment.