This commit is contained in:
2016-08-08 14:47:35 -04:00
commit 0b0cb7c73a
156 changed files with 114318 additions and 0 deletions
@@ -0,0 +1,53 @@
using System.Threading.Tasks;
using System.Web.Mvc;
using InventoryTraker.Web.Identity;
using InventoryTraker.Web.Models;
using Microsoft.AspNet.Identity;
using Microsoft.Owin.Security;
using Microsoft.Web.Mvc;
namespace InventoryTraker.Web.Controllers
{
[AllowAnonymous]
public class AuthenticationController : ControllerBase
{
private readonly ApplicationUserManager _userManager;
private readonly IAuthenticationManager _authManager;
public AuthenticationController(ApplicationUserManager userManager, IAuthenticationManager authManager)
{
_userManager = userManager;
_authManager = authManager;
}
public ActionResult Login()
{
return View();
}
[HttpPost]
public async Task<ActionResult> Login(LoginForm form)
{
var user = await _userManager.FindByEmailAsync(form.EmailAddress);
if (user == null || ! await _userManager.CheckPasswordAsync(user, form.Password))
{
Response.StatusCode = 400;
return Json("The username or password is invalid.");
}
var identity = _userManager.CreateIdentity(user, DefaultAuthenticationTypes.ApplicationCookie);
_authManager.SignIn(new AuthenticationProperties { IsPersistent = false }, identity);
return Json(true);
}
public ActionResult Logout()
{
_authManager.SignOut();
return this.RedirectToAction<HomeController>(c => c.Index());
}
}
}
@@ -0,0 +1,13 @@
using System.Web.Mvc;
using InventoryTraker.Web.ActionResults;
namespace InventoryTraker.Web.Controllers
{
public abstract class ControllerBase : Controller
{
public BetterJsonResult<T> BetterJson<T>(T model)
{
return new BetterJsonResult<T>() {Data = model};
}
}
}
@@ -0,0 +1,57 @@
using System.Linq;
using System.Web.Mvc;
using AutoMapper;
using AutoMapper.QueryableExtensions;
using InventoryTraker.Web.Core;
using InventoryTraker.Web.Data;
using InventoryTraker.Web.Models;
namespace InventoryTraker.Web.Controllers
{
public class CustomerController : ControllerBase
{
private readonly AppDbContext _context;
public CustomerController(AppDbContext context)
{
_context = context;
}
public ActionResult Index()
{
return View();
}
public JsonResult All()
{
var customerModels = _context.Customers
.OrderByDescending(x => x.CreateDate)
.ProjectTo<CustomerViewModel>();
return BetterJson(customerModels.ToArray());
}
public JsonResult Add(AddCustomerForm form)
{
var customer = Mapper.Map<Customer>(form);
_context.Customers.Add(customer);
_context.SaveChanges();
var model = Mapper.Map<CustomerViewModel>(customer);
return BetterJson(model);
}
public JsonResult Update(EditCustomerForm form)
{
var target = _context.Customers.Find(form.Id);
Mapper.Map(form, target);
_context.SaveChanges();
var updatedCustomer = _context.Customers.ProjectTo<CustomerViewModel>().Single(x => x.Id == form.Id);
return BetterJson(updatedCustomer);
}
}
}
@@ -0,0 +1,12 @@
using System.Web.Mvc;
namespace InventoryTraker.Web.Controllers
{
public class HomeController : ControllerBase
{
public ActionResult Index()
{
return View();
}
}
}
@@ -0,0 +1,44 @@
using System.Linq;
using System.Web.Mvc;
using AutoMapper;
using AutoMapper.QueryableExtensions;
using InventoryTraker.Web.Core;
using InventoryTraker.Web.Data;
using InventoryTraker.Web.Models;
namespace InventoryTraker.Web.Controllers
{
public class InventoryController : ControllerBase
{
private readonly AppDbContext _context;
public InventoryController(AppDbContext context)
{
_context = context;
}
public ActionResult Index()
{
return View();
}
public JsonResult All()
{
var customerModels = _context.Inventories
.OrderByDescending(x => x.InventoryType.Name)
.ProjectTo<InventoryViewModel>();
return BetterJson(customerModels.ToArray());
}
public JsonResult Arrival(AddCustomerForm form)
{
var customer = Mapper.Map<Customer>(form);
_context.Customers.Add(customer);
_context.SaveChanges();
var model = Mapper.Map<CustomerViewModel>(customer);
return BetterJson(model);
}
}
}
@@ -0,0 +1,42 @@
using System.Data.Entity;
using System.Linq;
using System.Web.Mvc;
using AutoMapper;
using AutoMapper.QueryableExtensions;
using InventoryTraker.Web.Core;
using InventoryTraker.Web.Data;
using InventoryTraker.Web.Models;
namespace InventoryTraker.Web.Controllers
{
public class OpportunityController : ControllerBase
{
private readonly AppDbContext _context;
public OpportunityController(AppDbContext context)
{
_context = context;
}
public ViewResult Index()
{
var models = _context.Opportunities.ProjectTo<OpportunityViewModel>().ToArray();
return View(models);
}
public JsonResult Add(AddOpportunityForm form)
{
var customer = _context.Customers.Include(x => x.Opportunities).Single(x => x.Id == form.CustomerId);
var opportunity = Mapper.Map<Opportunity>(form);
customer.Opportunities.Add(opportunity);
_context.SaveChanges();
var model = Mapper.Map<CustomerOpportunityViewModel>(opportunity);
return BetterJson(model);
}
}
}
@@ -0,0 +1,35 @@
using System.Web.Mvc;
using AutoMapper;
using InventoryTraker.Web.Identity;
using InventoryTraker.Web.Models;
using Microsoft.AspNet.Identity;
namespace InventoryTraker.Web.Controllers
{
public class ProfileController : ControllerBase
{
private readonly ApplicationUserManager _userManager;
public ProfileController(ApplicationUserManager userManager)
{
_userManager = userManager;
}
public ActionResult Index()
{
var user = _userManager.FindById(User.Identity.GetUserId());
var model = Mapper.Map<ProfileForm>(user);
return View(model);
}
public JsonResult Update(ProfileForm form)
{
var user = _userManager.FindById(User.Identity.GetUserId());
user.Email = form.EmailAddress;
user.UserName = form.FullName;
_userManager.Update(user);
return Json(true);
}
}
}
@@ -0,0 +1,47 @@
using System;
using System.Linq;
using System.Web.Mvc;
using AutoMapper.QueryableExtensions;
using InventoryTraker.Web.Data;
using InventoryTraker.Web.Models;
using InventoryTraker.Web.Utilities;
namespace InventoryTraker.Web.Controllers
{
public class ReportController : ControllerBase
{
private readonly AppDbContext _context;
public ReportController(AppDbContext context)
{
_context = context;
}
public ActionResult Index()
{
return View();
}
public JsonResult NewCustomers()
{
var startOfMonth = DateTime.Today.ToStartOfMonth();
var endOfMonth = DateTime.Today.ToEndOfMonth();
var customers = _context.Customers.Where(x => x.CreateDate >= startOfMonth && x.CreateDate <= endOfMonth)
.ProjectTo<NewCustomerReportViewModel>().ToArray();
return BetterJson(customers);
}
public JsonResult LostCustomers()
{
var startOfMonth = DateTime.Today.ToStartOfMonth();
var endOfMonth = DateTime.Today.ToEndOfMonth();
var customers = _context.Customers.Where(x => x.TerminationDate >= startOfMonth && x.TerminationDate <= endOfMonth)
.ProjectTo<LostCustomerReportViewModel>().ToArray();
return Json(customers);
}
}
}
@@ -0,0 +1,42 @@
using System.Data.Entity;
using System.Linq;
using System.Web.Mvc;
using AutoMapper;
using AutoMapper.QueryableExtensions;
using InventoryTraker.Web.Core;
using InventoryTraker.Web.Data;
using InventoryTraker.Web.Models;
namespace InventoryTraker.Web.Controllers
{
public class RiskController : ControllerBase
{
private readonly AppDbContext _context;
public RiskController(AppDbContext context)
{
_context = context;
}
public ViewResult Index()
{
var models = _context.Risks.ProjectTo<RiskViewModel>().ToArray();
return View(models);
}
public JsonResult Add(AddRiskForm form)
{
var customer = _context.Customers.Include(x => x.Risks).Single(x => x.Id == form.CustomerId);
var risk = Mapper.Map<Risk>(form);
customer.Risks.Add(risk);
_context.SaveChanges();
var model = Mapper.Map<CustomerRiskViewModel>(risk);
return BetterJson(model);
}
}
}
@@ -0,0 +1,12 @@
using System.Web.Mvc;
namespace InventoryTraker.Web.Controllers
{
public class TemplateController : ControllerBase
{
public PartialViewResult Render(string feature, string name)
{
return PartialView($"~/js/{feature}/templates/{name}");
}
}
}