Skip to content

Instantly share code, notes, and snippets.

@ekumachidi
Last active May 1, 2017 01:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ekumachidi/32b29b2cc29a9bb8a0614818e128e2ba to your computer and use it in GitHub Desktop.
Save ekumachidi/32b29b2cc29a9bb8a0614818e128e2ba to your computer and use it in GitHub Desktop.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
using VendorManagement.DAL.Data;
using VendorManagement.Model;
namespace VendorManagement.WebUI.Controllers
{
public class PaymentSchedulesController : Controller
{
private DataContext db = new DataContext();
// GET: PaymentSchedules
public ActionResult Index()
{
var paymentSchedules = db.PaymentSchedules.Include(p => p.Contracts);
return View(paymentSchedules.ToList());
}
// GET: PaymentSchedules/Details/5
public ActionResult Details(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
PaymentSchedule paymentSchedule = db.PaymentSchedules.Find(id);
if (paymentSchedule == null)
{
return HttpNotFound();
}
return View(paymentSchedule);
}
// GET: PaymentSchedules/Create
public ActionResult Create()
{
ViewBag.ContractId = new SelectList(db.Contracts, "ContractId", "Comment");
ViewBag.Period = new SelectList(GetPeriod(), "Period");
return View();
}
public ActionResult Generate()
{
GetPeriod();
return View();
}
[HttpPost]
public ActionResult Generate(PaymentSchedule paymentSchedule)
{
var contracts = db.Contracts.ToList();
foreach (var contract in contracts)
{
paymentSchedule.ContractId = contract.ContractId;
paymentSchedule.Period = paymentSchedule.Period;
paymentSchedule.Cost = contract.Renumeration;
paymentSchedule.Adjustment = "0";
paymentSchedule.Final = (int.Parse(paymentSchedule.Cost) - int.Parse(paymentSchedule.Adjustment)).ToString();
paymentSchedule.Locked = true;
db.PaymentSchedules.Add(paymentSchedule);
}
db.SaveChanges();
return RedirectToAction("Index");
}
public void getPeriod()
{
List<string> period = new List<string>();
for (int year = int.Parse(DateTime.Now.AddYears(-5).Year.ToString()); year < int.Parse(DateTime.Now.AddYears(10).Year.ToString()); year++)
{
foreach (Quarter quarter in Enum.GetValues(typeof(Quarter)))
{
period.Add(quarter + " " + year);
}
}
}
public IEnumerable<SelectListItem> GetPeriod()
{
List<string> period = new List<string>();
for (int year = int.Parse(DateTime.Now.AddYears(-5).Year.ToString()); year < int.Parse(DateTime.Now.AddYears(2).Year.ToString()); year++)
{
foreach (Quarter quarter in Enum.GetValues(typeof(Quarter)))
{
period.Add(quarter + " " + year);
}
}
return period.ToList();
}
public ActionResult Generate()
{
ViewBag.Period = new SelectList(GetPeriod(), "Period");
return ViewBag.Period = new SelectList(period);
}
// GET: PaymentSchedules/Create
public ActionResult Create()
{
ViewBag.ContractId = new SelectList(db.Contracts, "ContractId", "Comment");
return View();
}
[HttpPost]
public ActionResult Generate(PaymentSchedule paymentSchedule)
{
//var payPeriod = paymentSchedule.Period;
var contracts = db.Contracts;
var cont = contracts.ToList();
foreach (var contract in contracts)
{
paymentSchedule.ContractId = contract.ContractId;
paymentSchedule.Cost = contract.Renumeration;
paymentSchedule.Adjustment = "0";
paymentSchedule.Final = "0" ;//(int.Parse(paymentSchedule.Cost) - int.Parse(paymentSchedule.Adjustment)).ToString();
paymentSchedule.Locked = true;
paymentSchedule.Period = paymentSchedule.Period;
db.PaymentSchedules.Add(paymentSchedule);
}db.SaveChanges();
return RedirectToAction("Index");
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include = "PaymentScheduleId,ContractId,Period,Cost,Adjustment,Final,Locked")] PaymentSchedule paymentSchedule)
{
if (ModelState.IsValid)
{
db.PaymentSchedules.Add(paymentSchedule);
db.SaveChanges();
return RedirectToAction("Index");
}
ViewBag.ContractId = new SelectList(db.Contracts, "ContractId", "Comment", paymentSchedule.ContractId);
return View(paymentSchedule);
}
// GET: PaymentSchedules/Edit/5
public ActionResult Edit(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
PaymentSchedule paymentSchedule = db.PaymentSchedules.Find(id);
if (paymentSchedule == null)
{
return HttpNotFound();
}
ViewBag.ContractId = new SelectList(db.Contracts, "ContractId", "Comment", paymentSchedule.ContractId);
return View(paymentSchedule);
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit([Bind(Include = "PaymentScheduleId,ContractId,Period,Cost,Adjustment,Final,Locked")] PaymentSchedule paymentSchedule)
{
if (ModelState.IsValid)
{
db.Entry(paymentSchedule).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
ViewBag.ContractId = new SelectList(db.Contracts, "ContractId", "Comment", paymentSchedule.ContractId);
return View(paymentSchedule);
}
// GET: PaymentSchedules/Delete/5
public ActionResult Delete(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
PaymentSchedule paymentSchedule = db.PaymentSchedules.Find(id);
if (paymentSchedule == null)
{
return HttpNotFound();
}
return View(paymentSchedule);
}
// POST: PaymentSchedules/Delete/5
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public ActionResult DeleteConfirmed(int id)
{
PaymentSchedule paymentSchedule = db.PaymentSchedules.Find(id);
db.PaymentSchedules.Remove(paymentSchedule);
db.SaveChanges();
return RedirectToAction("Index");
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
db.Dispose();
}
base.Dispose(disposing);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment