Tushar Mahajan

Tushar Mahajan

  • NA
  • 61
  • 1.2k

Attendance Management System

Jan 28 2019 7:09 AM
using AMS.Model;
using AttendenceManagementSystem.Service;
using System;
using System.Collections.Generic;
using System.Web.Mvc;
namespace AttendenceManagementSystem.Controllers
{
public class EmployeePunchController : Controller
{
// GET: EmployeePunch
EmployeePunchService PunchService;
public EmployeePunchController()
{
PunchService = new EmployeePunchService();
}
public ActionResult EmployeePunch()
{
List<EmployeePunchDto> EmployeePunch = PunchService.GetAllEmployeesId();
return View(EmployeePunch);
}
public ActionResult PunchIn(int ID)
{
EmployeePunchDto objlist = new EmployeePunchDto();
objlist.EmployeeID = ID;
objlist.PunchIn = DateTime.Now;
objlist.Type = "In";
bool model = PunchService.AddEmployeePunchData(objlist);
//return RedirectToAction("EmployeeDetails", "Employee");
return RedirectToAction("EmployeePunch");
}
public ActionResult PunchOut(int ID)
{
EmployeePunchDto objlist = new EmployeePunchDto();
objlist.EmployeeID = ID;
objlist.PunchIn = DateTime.Now;
objlist.Type = "Out";
bool model = PunchService.AddEmployeePunchData(objlist);
//return RedirectToAction("EmployeeDetails", "Employee");
return RedirectToAction("EmployeePunch");
}
public ActionResult MarkAttendence(int id)
{
//DropDown List Fort Hours
List<SelectListItem> hourlist = new List<SelectListItem>();
hourlist.Add(new SelectListItem { Text = "12:00 am", Value = "0" });
hourlist.Add(new SelectListItem { Text = "1:00 am", Value = "1" });
hourlist.Add(new SelectListItem { Text = "2:00 am", Value = "2" });
hourlist.Add(new SelectListItem { Text = "3:00 am", Value = "3" });
hourlist.Add(new SelectListItem { Text = "4:00 am", Value = "4" });
hourlist.Add(new SelectListItem { Text = "5:00 am", Value = "5" });
hourlist.Add(new SelectListItem { Text = "6:00 am", Value = "6" });
hourlist.Add(new SelectListItem { Text = "7:00 am", Value = "7" });
hourlist.Add(new SelectListItem { Text = "8:00 am", Value = "8" });
hourlist.Add(new SelectListItem { Text = "9:00 am", Value = "9" });
hourlist.Add(new SelectListItem { Text = "10:00 am", Value = "10" });
hourlist.Add(new SelectListItem { Text = "11:00 am", Value = "11" });
hourlist.Add(new SelectListItem { Text = "12:00 pm", Value = "12" });
hourlist.Add(new SelectListItem { Text = "1:00 pm", Value = "13" });
hourlist.Add(new SelectListItem { Text = "2:00 pm", Value = "14" });
hourlist.Add(new SelectListItem { Text = "3:00 pm", Value = "15" });
hourlist.Add(new SelectListItem { Text = "4:00 pm", Value = "16" });
hourlist.Add(new SelectListItem { Text = "5:00 pm", Value = "17" });
hourlist.Add(new SelectListItem { Text = "6:00 pm", Value = "18" });
hourlist.Add(new SelectListItem { Text = "7:00 pm", Value = "19" });
hourlist.Add(new SelectListItem { Text = "8:00 pm", Value = "20" });
hourlist.Add(new SelectListItem { Text = "9:00 pm", Value = "21" });
hourlist.Add(new SelectListItem { Text = "10:00 pm", Value = "22" });
hourlist.Add(new SelectListItem { Text = "11:00 pm", Value = "23" });
ViewBag.TitleList = hourlist;
//DropDown List Fort Minutes
List<SelectListItem> minutelist = new List<SelectListItem>();
minutelist.Add(new SelectListItem { Text = "00", Value = "0" });
minutelist.Add(new SelectListItem { Text = "01", Value = "1" });
minutelist.Add(new SelectListItem { Text = "02", Value = "2" });
minutelist.Add(new SelectListItem { Text = "03", Value = "3" });
minutelist.Add(new SelectListItem { Text = "04", Value = "4" });
minutelist.Add(new SelectListItem { Text = "05", Value = "5" });
minutelist.Add(new SelectListItem { Text = "06", Value = "6" });
minutelist.Add(new SelectListItem { Text = "07", Value = "7" });
minutelist.Add(new SelectListItem { Text = "08", Value = "8" });
minutelist.Add(new SelectListItem { Text = "09", Value = "9" });
minutelist.Add(new SelectListItem { Text = "10", Value = "10" });
minutelist.Add(new SelectListItem { Text = "11", Value = "11" });
minutelist.Add(new SelectListItem { Text = "12", Value = "12" });
minutelist.Add(new SelectListItem { Text = "13", Value = "13" });
minutelist.Add(new SelectListItem { Text = "14", Value = "14" });
minutelist.Add(new SelectListItem { Text = "15", Value = "15" });
minutelist.Add(new SelectListItem { Text = "16", Value = "16" });
minutelist.Add(new SelectListItem { Text = "17", Value = "17" });
minutelist.Add(new SelectListItem { Text = "18", Value = "18" });
minutelist.Add(new SelectListItem { Text = "19", Value = "19" });
minutelist.Add(new SelectListItem { Text = "20", Value = "20" });
minutelist.Add(new SelectListItem { Text = "21", Value = "21" });
minutelist.Add(new SelectListItem { Text = "22", Value = "22" });
minutelist.Add(new SelectListItem { Text = "23", Value = "23" });
minutelist.Add(new SelectListItem { Text = "24", Value = "24" });
minutelist.Add(new SelectListItem { Text = "25", Value = "25" });
minutelist.Add(new SelectListItem { Text = "26", Value = "26" });
minutelist.Add(new SelectListItem { Text = "27", Value = "27" });
minutelist.Add(new SelectListItem { Text = "28", Value = "28" });
minutelist.Add(new SelectListItem { Text = "29", Value = "29" });
minutelist.Add(new SelectListItem { Text = "30", Value = "30" });
minutelist.Add(new SelectListItem { Text = "31", Value = "31" });
minutelist.Add(new SelectListItem { Text = "32", Value = "32" });
minutelist.Add(new SelectListItem { Text = "33", Value = "33" });
minutelist.Add(new SelectListItem { Text = "34", Value = "34" });
minutelist.Add(new SelectListItem { Text = "35", Value = "35" });
minutelist.Add(new SelectListItem { Text = "36", Value = "36" });
minutelist.Add(new SelectListItem { Text = "37", Value = "37" });
minutelist.Add(new SelectListItem { Text = "38", Value = "38" });
minutelist.Add(new SelectListItem { Text = "39", Value = "39" });
minutelist.Add(new SelectListItem { Text = "40", Value = "40" });
minutelist.Add(new SelectListItem { Text = "41", Value = "41" });
minutelist.Add(new SelectListItem { Text = "42", Value = "42" });
minutelist.Add(new SelectListItem { Text = "43", Value = "43" });
minutelist.Add(new SelectListItem { Text = "44", Value = "44" });
minutelist.Add(new SelectListItem { Text = "45", Value = "45" });
minutelist.Add(new SelectListItem { Text = "46", Value = "46" });
minutelist.Add(new SelectListItem { Text = "47", Value = "47" });
minutelist.Add(new SelectListItem { Text = "48", Value = "48" });
minutelist.Add(new SelectListItem { Text = "49", Value = "49" });
minutelist.Add(new SelectListItem { Text = "50", Value = "50" });
minutelist.Add(new SelectListItem { Text = "51", Value = "51" });
minutelist.Add(new SelectListItem { Text = "52", Value = "52" });
minutelist.Add(new SelectListItem { Text = "53", Value = "53" });
minutelist.Add(new SelectListItem { Text = "54", Value = "54" });
minutelist.Add(new SelectListItem { Text = "55", Value = "55" });
minutelist.Add(new SelectListItem { Text = "56", Value = "56" });
minutelist.Add(new SelectListItem { Text = "57", Value = "57" });
minutelist.Add(new SelectListItem { Text = "58", Value = "58" });
minutelist.Add(new SelectListItem { Text = "59", Value = "59" });
ViewBag.TitleList = minutelist;
ManualPunchVM model = PunchService.GetEmployeePunchDetail(id);
return View(model);
}
[HttpPost]
public ActionResult MarkAttendence(ManualPunchVM model, string SubmitTime)
{
model.HourIn = model.HourIn.HasValue ? model.HourIn.Value : 0;
model.MinutesIn = model.MinutesIn.HasValue ? model.MinutesIn.Value : 0;
model.HourOut = model.HourOut.HasValue ? model.HourOut.Value : 0;
model.MinutesOut = model.MinutesOut.HasValue ? model.MinutesOut.Value : 0;
EmployeePunchDto objlist = new EmployeePunchDto();
objlist.EmployeeID = model.EmployeeID;
//DateTime currentDate = DateTime.Now.Date;
//objlist.PunchIn = currentDate.AddHours((int)model.HourIn).AddMinutes((int)model.MinutesIn);
//objlist.PunchIn = currentDate.AddHours((int)model.HourOut).AddMinutes((int)model.MinutesOut);
if (SubmitTime == "Punch In")
{
objlist.Type = "In";
objlist.PunchIn = model.PunchDate.AddHours((int)model.HourIn).AddMinutes((int)model.MinutesIn);
}
else
{
objlist.Type = "Out";
objlist.PunchIn = model.PunchDate.AddHours((int)model.HourOut).AddMinutes((int)model.MinutesOut);
}
bool isSaved = PunchService.AddEmployeePunchData(objlist);
return RedirectToAction("EmployeePunch", new { id = model.EmployeeID });
}
}
}

Attachment: Controllers.rar

Answers (2)