public ActionResult Create([Bind(Include = "EmployeeID,EmployeeFirstName,EmployeeLastName,EmployeeEmail")] Employee employee) { foreach (Role r in db.Roles) { string[] tmp = r.RoleName.Split(' '); string key = ""; foreach (string x in tmp) { key += x; } bool exist = Convert.ToBoolean(Request.Form[key].Split(',')[0]); if (exist) { db.EmployeeRoles.Add(new EmployeeRole { Employee = employee, Role = r, CreateDate = DateTime.Now, UpdateDate = DateTime.Now }); } } if (ModelState.IsValid) { string password = Membership.GeneratePassword(10, 3); employee.CreateDate = DateTime.Now; employee.UpdateDate = DateTime.Now; employee.PasswordHash = getHashedPassword(password); db.Employees.Add(employee); db.SaveChanges(); sendMailToNewEmployee(employee.EmployeeID, password); return(RedirectToAction("Index")); } return(View(employee)); }
public ActionResult ProcessRequest(int id, FormCollection collection) { try { LeaveRequestInfo lri = db.LeaveRequestInfo.Find(id); LeaveRequestDescription lrd = getLatestDescription(lri); string description = Convert.ToString(collection["deliveryManagerComment"]); string status = Convert.ToString(collection["deliveryManagerStatusID"]); lrd.DeliveryManagerComment = description; lrd.DeliveryManagerStatus = db.RequestStatus.Find(Convert.ToInt32(status)); db.SaveChanges(); int employeeID = db.LeaveRequestInfo.Find(id).Employee.EmployeeID; if (!lrd.DeliveryManagerStatus.RequestStatusName.Equals("Pending")) { sendMailToEmployee(db.LeaveRequestInfo.Find(id).Employee.EmployeeID); } if (lrd.DeliveryManagerStatus.RequestStatusName.Equals("Approved")) { sendMailToDepartmentManager(lri, lrd); } return(RedirectToAction("Index")); } catch { return(RedirectToAction("ProcessRequest")); } }
public ActionResult Create([Bind(Include = "lID,deliveryManagerID,deliveryManagerApproved,deliveryManagerComment")] DeliveryManagerLeaveRequestViewModel deliveryManagerLeaveRequestViewModel) { if (ModelState.IsValid) { db.DeliveryManagerLeaveRequestViewModels.Add(deliveryManagerLeaveRequestViewModel); //get data from create and write in main database var managerID = deliveryManagerLeaveRequestViewModel.deliveryManagerID; var isApprowed = deliveryManagerLeaveRequestViewModel.deliveryManagerApproved; var comment = deliveryManagerLeaveRequestViewModel.deliveryManagerComment; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(deliveryManagerLeaveRequestViewModel)); }
private void removeAllTables(LeaveManagerContext db) { foreach (var e in db.Employees) { db.Employees.Remove(e); } foreach (var e in db.EmployeeRoles) { db.EmployeeRoles.Remove(e); } foreach (var e in db.LeaveReasons) { db.LeaveReasons.Remove(e); } foreach (var e in db.RequestStatus) { db.RequestStatus.Remove(e); } foreach (var e in db.Roles) { db.Roles.Remove(e); } db.SaveChanges(); }
public ActionResult Create([Bind(Include = "leaveRequestID,employeeID,allDayEvent,startTime,endTime,leaveReasonID,Description,deliveryManagerID,deliveryManagerApproved,departmentManagerID,departmentManagerApproved,requestStatusID")] LeaveRequest leaveRequest) { if (ModelState.IsValid) { db.LeaveRequests.Add(leaveRequest); db.SaveChanges(); return(RedirectToAction("Index")); } /* ViewBag.departmentManagerID = new SelectList(db.Employees, "departmentManagerID", "employeeName", leaveRequest.departmentManagerID); * ViewBag.deliveryManagerID = new SelectList(db.Employees, "deliveryManagerID", "employeeName", leaveRequest.deliveryManagerID); * ViewBag.employeeID = new SelectList(db.Employees, "employeeID", "employeeName", leaveRequest.employeeID); * ViewBag.leaveReasonID = new SelectList(db.LeaveReasons, "leaveReasonID", "leaveReasonName", leaveRequest.leaveReasonID); * ViewBag.requestStatusID = new SelectList(db.RequestStatus, "requestStatusID", "requestStatusName", leaveRequest.requestStatusID);*/ return(View(leaveRequest)); }
public ActionResult ProcessRequest(int id, FormCollection collection) { // TODO: Add update logic here try { LeaveRequest lr = db.LeaveRequests.Find(id); string description = Convert.ToString(collection["deliveryManagerComment"]); string status = Convert.ToString(collection["deliveryManagerStatusID"]); lr.deliveryManagerComment = description; lr.deliveryManagerStatus = db.RequestStatus.Find(Convert.ToInt32(status)); db.SaveChanges(); //Send Mail //int employeeID = db.LeaveRequests.Find(id).employee.employeeID; //sendMailToEmployee(db.LeaveRequests.Find(id).employee.employeeID); //if (status.Equals("Approved")) //{ // sendMailToDepartmentManager(db.LeaveRequests.Find(id)); //} return(RedirectToAction("Index")); } catch { return(RedirectToAction("ProcessRequest")); } }
public ActionResult Edit([Bind(Include = "MailSettingsID,Host,Port,Username,Password")] MailSettings mailSettings) { if (ModelState.IsValid) { db.Entry(mailSettings).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(mailSettings)); }
public ActionResult Create([Bind(Include = "leaveRequestID,employeeName,deliveryManagerName,departmentManagerName,allDayEvent,startTime,endTime,leaveReasonID,Description,deliveryManagerID,departmentManagerID")] EmployeeLeaveRequestViewModel employeeLeaveRequestViewModel) { if (!serverValidation(employeeLeaveRequestViewModel)) { ViewBag.leaveReasonID = new SelectList(db.LeaveReasons, "leaveReasonID", "leaveReasonName"); return(View(employeeLeaveRequestViewModel)); } LeaveRequest newLeaveRequest = mapLeaveRequestViewModel(employeeLeaveRequestViewModel); newLeaveRequest.CreateDate = DateTime.Now; if (ModelState.IsValid) { db.LeaveRequests.Add(newLeaveRequest); db.SaveChanges(); //int newRequestID = newLeaveRequest.leaveRequestID; //sendMailToDeliveryManager(getEmployeeIDByName(employeeLeaveRequestViewModel.deliveryManagerName), newLeaveRequest); return(RedirectToAction("Index")); } return(View(employeeLeaveRequestViewModel)); }
public ActionResult Create([Bind(Include = "leaveRequestID,employeeName,deliveryManagerName,departmentManagerName,allDayEvent,startTime,endTime,leaveReasonID,Description,deliveryManagerID,departmentManagerID")] EmployeeLeaveRequestViewModel employeeLeaveRequestViewModel) { if (!serverValidation(employeeLeaveRequestViewModel)) { ViewBag.leaveReasonID = new SelectList(db.LeaveReasons, "leaveReasonID", "leaveReasonName"); return(View(employeeLeaveRequestViewModel)); } LeaveRequestInfo newLeaveRequest = mapViewModelToLeaveRequestInfo(employeeLeaveRequestViewModel); LeaveRequestDescription newLeaveRequestDesc = mapViewModelToLeaveRequestDesc(employeeLeaveRequestViewModel, newLeaveRequest); if (ModelState.IsValid) { db.LeaveRequestInfo.Add(newLeaveRequest); db.LeaveRequestDescription.Add(newLeaveRequestDesc); db.SaveChanges(); sendMailToDeliveryManager(newLeaveRequest, newLeaveRequestDesc); return(RedirectToAction("Index")); } return(View(employeeLeaveRequestViewModel)); }
public ActionResult Edit([Bind(Include = "MailSettingsID,Host,Port,Username,Password")] MailSettings mailSettings) { if (ModelState.IsValid) { mailSettings.CreateDate = db.MailSettings.Find(mailSettings.MailSettingsID).CreateDate; mailSettings.UpdateDate = DateTime.Now; db.MailSettings.Find(mailSettings.MailSettingsID).Host = mailSettings.Host; db.MailSettings.Find(mailSettings.MailSettingsID).Port = mailSettings.Port; db.MailSettings.Find(mailSettings.MailSettingsID).Username = mailSettings.Username; db.MailSettings.Find(mailSettings.MailSettingsID).Password = mailSettings.Password; db.MailSettings.Find(mailSettings.MailSettingsID).UpdateDate = DateTime.Now; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(mailSettings)); }
public ActionResult ProcessRequest([Bind(Include = "leaveRequestID,departmentManagerComment,departmentManagerStatusID")] DepartmentManagerLeaveRequestViewModel departmentManagerLeaveRequestViewModel) { if (ModelState.IsValid) { LeaveRequestInfo requestToUpdate = db.LeaveRequestInfo.Find(departmentManagerLeaveRequestViewModel.LeaveRequestID); LeaveRequestDescription descToUpdate = EmployeeLeaveRequestViewModelsController.getLatestDescription(requestToUpdate, db); descToUpdate.DepartmentManagerComment = departmentManagerLeaveRequestViewModel.DepartmentManagerComment; descToUpdate.DepartmentManagerStatus = db.RequestStatus.Find(departmentManagerLeaveRequestViewModel.DepartmentManagerStatusID); db.SaveChanges(); if (!descToUpdate.DepartmentManagerStatus.RequestStatusName.Equals("Pending")) { sendMailToEmployee(requestToUpdate.Employee.EmployeeID); } return(RedirectToAction("Index")); } return(View()); }
public ActionResult ProcessRequest([Bind(Include = "leaveRequestID,departmentManagerComment,departmentManagerStatusID")] DepartmentManagerLeaveRequestViewModel departmentManagerLeaveRequestViewModel) { if (ModelState.IsValid) { var requestToUpdate = db.LeaveRequests.Find(departmentManagerLeaveRequestViewModel.leaveRequestID); requestToUpdate.departmentManagerComment = departmentManagerLeaveRequestViewModel.departmentManagerComment; requestToUpdate.departmentManagerStatus = db.RequestStatus.Find(departmentManagerLeaveRequestViewModel.departmentManagerStatusID); db.SaveChanges(); if (!requestToUpdate.departmentManagerStatus.requestStatusName.Equals("Pending")) { sendMailToEmployee(db.LeaveRequests.Find(requestToUpdate.leaveRequestID).employee.employeeID); } return(RedirectToAction("Index")); } return(View()); }
public ActionResult ForgottenPassword([Bind(Include = "email")] LoginViewModel loginViewModel) { var r = from l in db.Employees where l.EmployeeEmail == loginViewModel.Email select l; if (!r.Any()) { ViewBag.emailError = "Wrong email address."; return(View()); } else { Employee emp = r.First(); string password = Membership.GeneratePassword(10, 3); db.Employees.Single(e => e.EmployeeID == emp.EmployeeID).PasswordHash = EmployeesController.getHashedPassword(password); db.SaveChanges(); sendMailWithNewPass(emp, password); TempData["resetSuccess"] = "New password is send to your email address."; return(RedirectToAction("Index")); } }
private void populateDatabase(LeaveManagerContext db) { Employee e1 = new Employee { EmployeeFirstName = "Pera", EmployeeLastName = "Peric", EmployeeEmail = "*****@*****.**", PasswordHash = EmployeesController.getHashedPassword("pera"), CreateDate = DateTime.Now, UpdateDate = DateTime.Now }; Employee e2 = new Employee { EmployeeFirstName = "Mitar", EmployeeLastName = "Mitric", EmployeeEmail = "*****@*****.**", PasswordHash = EmployeesController.getHashedPassword("mitar"), CreateDate = DateTime.Now, UpdateDate = DateTime.Now }; Employee e3 = new Employee { EmployeeFirstName = "Zika", EmployeeLastName = "Zikic", EmployeeEmail = "*****@*****.**", PasswordHash = EmployeesController.getHashedPassword("zika"), CreateDate = DateTime.Now, UpdateDate = DateTime.Now }; Employee e4 = new Employee { EmployeeFirstName = "Marina", EmployeeLastName = "Maric", EmployeeEmail = "*****@*****.**", PasswordHash = EmployeesController.getHashedPassword("marina"), CreateDate = DateTime.Now, UpdateDate = DateTime.Now }; Employee e5 = new Employee { EmployeeFirstName = "Maja", EmployeeLastName = "Majic", EmployeeEmail = "*****@*****.**", PasswordHash = EmployeesController.getHashedPassword("maja"), CreateDate = DateTime.Now, UpdateDate = DateTime.Now }; Employee e6 = new Employee { EmployeeFirstName = "Nikola", EmployeeLastName = "Nikolic", EmployeeEmail = "*****@*****.**", PasswordHash = EmployeesController.getHashedPassword("nikola"), CreateDate = DateTime.Now, UpdateDate = DateTime.Now }; Employee e7 = new Employee { EmployeeFirstName = "Marko", EmployeeLastName = "Markovic", EmployeeEmail = "*****@*****.**", PasswordHash = EmployeesController.getHashedPassword("marko"), CreateDate = DateTime.Now, UpdateDate = DateTime.Now }; db.Employees.AddOrUpdate(e1, e2, e3, e4, e5, e6, e7); Role r1 = new Role { RoleName = "Worker", CreateDate = DateTime.Now, UpdateDate = DateTime.Now }; Role r2 = new Role { RoleName = "Delivery Manager", CreateDate = DateTime.Now, UpdateDate = DateTime.Now }; Role r3 = new Role { RoleName = "Department Manager", CreateDate = DateTime.Now, UpdateDate = DateTime.Now }; Role r4 = new Role { RoleName = "Super User", CreateDate = DateTime.Now, UpdateDate = DateTime.Now }; db.Roles.AddOrUpdate(r1, r2, r3, r4); EmployeeRole er1 = new EmployeeRole { Employee = e1, Role = r1, CreateDate = DateTime.Now, UpdateDate = DateTime.Now }; EmployeeRole er2 = new EmployeeRole { Employee = e2, Role = r1, CreateDate = DateTime.Now, UpdateDate = DateTime.Now }; EmployeeRole er3 = new EmployeeRole { Employee = e2, Role = r2, CreateDate = DateTime.Now, UpdateDate = DateTime.Now }; EmployeeRole er4 = new EmployeeRole { Employee = e3, Role = r2, CreateDate = DateTime.Now, UpdateDate = DateTime.Now }; EmployeeRole er5 = new EmployeeRole { Employee = e4, Role = r1, CreateDate = DateTime.Now, UpdateDate = DateTime.Now }; EmployeeRole er6 = new EmployeeRole { Employee = e5, Role = r1, CreateDate = DateTime.Now, UpdateDate = DateTime.Now }; EmployeeRole er7 = new EmployeeRole { Employee = e6, Role = r3, CreateDate = DateTime.Now, UpdateDate = DateTime.Now }; EmployeeRole er8 = new EmployeeRole { Employee = e7, Role = r4, CreateDate = DateTime.Now, UpdateDate = DateTime.Now }; db.EmployeeRoles.AddOrUpdate(er1, er2, er3, er4, er5, er6, er7, er8); LeaveReason lr1 = new LeaveReason() { LeaveReasonName = "Holiday", CreateDate = DateTime.Now, UpdateDate = DateTime.Now }; LeaveReason lr2 = new LeaveReason() { LeaveReasonName = "Sickness", CreateDate = DateTime.Now, UpdateDate = DateTime.Now }; LeaveReason lr3 = new LeaveReason() { LeaveReasonName = "Other reasons", CreateDate = DateTime.Now, UpdateDate = DateTime.Now }; db.LeaveReasons.AddOrUpdate(lr1, lr2, lr3); RequestStatus rs1 = new RequestStatus() { RequestStatusName = "Pending", CreateDate = DateTime.Now, UpdateDate = DateTime.Now }; RequestStatus rs2 = new RequestStatus() { RequestStatusName = "Approved", CreateDate = DateTime.Now, UpdateDate = DateTime.Now }; RequestStatus rs3 = new RequestStatus() { RequestStatusName = "Denied", CreateDate = DateTime.Now, UpdateDate = DateTime.Now }; db.RequestStatus.AddOrUpdate(rs1, rs2, rs3); db.SaveChanges(); }
protected override void Seed(LeaveManager.Models.LeaveManagerContext context) { // This method will be called after migrating to the latest version. // You can use the DbSet<T>.AddOrUpdate() helper extension method // to avoid creating duplicate seed data. E.g. // // context.People.AddOrUpdate( // p => p.FullName, // new Person { FullName = "Andrew Peters" }, // new Person { FullName = "Brice Lambson" }, // new Person { FullName = "Rowan Miller" } // ); // /*Employee e1 = new Employee { EmployeeID = 100, EmployeeFirstName = "Dzordz", EmployeeLastName = "Dzonson", EmployeeEmail = "*****@*****.**" }; * Employee e2 = new Employee { EmployeeID = 101, EmployeeFirstName = "Beni", EmployeeLastName = "Benic", EmployeeEmail = "*****@*****.**"}; * * Role r1 = new Role { RoleID = 100, RoleName = "TestRole1" }; * Role r2 = new Role { RoleID = 101, RoleName = "TestRole2" }; * * EmployeeRole er1 = new EmployeeRole {EmployeeRoleID = 100, Employee = e1, EmployeeID = e1.EmployeeID, Role = r1, RoleID = r1.RoleID}; * EmployeeRole er2 = new EmployeeRole { EmployeeRoleID = 101, Employee = e1, EmployeeID = e1.EmployeeID, Role = r2, RoleID = r2.RoleID }; * * LeaveReason lr1 = new LeaveReason { leaveReasonID = 101, LeaveReasonName = "sickness" }; * * * var db = new LeaveManagerContext(); * * db.Employees.AddOrUpdate(e1, e2); * db.Roles.AddOrUpdate(r1, r2); * db.EmployeeRoles.AddOrUpdate(er1); * db.SaveChanges();*/ /* * LeaveReason lr1 = new LeaveReason { LeaveReasonName = "died one more time" }; * RequestStatus rs1 = new RequestStatus { RequestStatusName = "pending" }; * var db = new LeaveManagerContext(); * db.LeaveReasons.Add(lr1); * db.RequestStatus.Add(rs1); * db.SaveChanges();*/ //Remove All Tables //var db = new LeaveManagerContext(); //removeAllTables(db); //Add data to database //var db = new LeaveManagerContext(); //populateDatabase(db); // Initial Mail Settings var db = new LeaveManagerContext(); MailSettings ms = new MailSettings { Host = "smtp.gmail.com", Port = 25, Username = "******", Password = "******", CreateDate = DateTime.Now, UpdateDate = DateTime.Now }; db.MailSettings.AddOrUpdate(ms); db.SaveChanges(); }
private void populateDatabase(LeaveManagerContext db) { Employee e1 = new Employee { employeeFirstName = "Pera", employeeLastName = "Peric", employeeEmail = "*****@*****.**", passwordHash = EmployeesController.getHashedPassword("pera"), CreateDate = DateTime.Now }; Employee e2 = new Employee { employeeFirstName = "Mitar", employeeLastName = "Mitric", employeeEmail = "*****@*****.**", passwordHash = EmployeesController.getHashedPassword("mitar"), CreateDate = DateTime.Now }; Employee e3 = new Employee { employeeFirstName = "Zika", employeeLastName = "Zikic", employeeEmail = "*****@*****.**", passwordHash = EmployeesController.getHashedPassword("zika"), CreateDate = DateTime.Now }; Employee e4 = new Employee { employeeFirstName = "Marina", employeeLastName = "Maric", employeeEmail = "*****@*****.**", passwordHash = EmployeesController.getHashedPassword("marina"), CreateDate = DateTime.Now }; Employee e5 = new Employee { employeeFirstName = "Maja", employeeLastName = "Majic", employeeEmail = "*****@*****.**", passwordHash = EmployeesController.getHashedPassword("maja"), CreateDate = DateTime.Now }; Employee e6 = new Employee { employeeFirstName = "Nikola", employeeLastName = "Nikolic", employeeEmail = "*****@*****.**", passwordHash = EmployeesController.getHashedPassword("nikola"), CreateDate = DateTime.Now }; Employee e7 = new Employee { employeeFirstName = "Marko", employeeLastName = "Markovic", employeeEmail = "*****@*****.**", passwordHash = EmployeesController.getHashedPassword("marko"), CreateDate = DateTime.Now }; db.Employees.AddOrUpdate(e1, e2, e3, e4, e5, e6, e7); Role r1 = new Role { roleName = "Worker", CreateDate = DateTime.Now }; Role r2 = new Role { roleName = "Delivery Manager", CreateDate = DateTime.Now }; Role r3 = new Role { roleName = "Department Manager", CreateDate = DateTime.Now }; Role r4 = new Role { roleName = "Super User", CreateDate = DateTime.Now }; db.Roles.AddOrUpdate(r1, r2, r3, r4); EmployeeRole er1 = new EmployeeRole { employee = e1, employeeID = e1.employeeID, role = r1, roleID = r1.roleID, CreateDate = DateTime.Now }; EmployeeRole er2 = new EmployeeRole { employee = e2, employeeID = e2.employeeID, role = r1, roleID = r1.roleID, CreateDate = DateTime.Now }; EmployeeRole er3 = new EmployeeRole { employee = e2, employeeID = e2.employeeID, role = r2, roleID = r2.roleID, CreateDate = DateTime.Now }; EmployeeRole er4 = new EmployeeRole { employee = e3, employeeID = e3.employeeID, role = r2, roleID = r2.roleID, CreateDate = DateTime.Now }; EmployeeRole er5 = new EmployeeRole { employee = e4, employeeID = e4.employeeID, role = r1, roleID = r1.roleID, CreateDate = DateTime.Now }; EmployeeRole er6 = new EmployeeRole { employee = e5, employeeID = e1.employeeID, role = r1, roleID = r1.roleID, CreateDate = DateTime.Now }; EmployeeRole er7 = new EmployeeRole { employee = e6, employeeID = e6.employeeID, role = r3, roleID = r3.roleID, CreateDate = DateTime.Now }; EmployeeRole er8 = new EmployeeRole { employee = e7, employeeID = e7.employeeID, role = r4, roleID = r4.roleID, CreateDate = DateTime.Now }; db.EmployeeRoles.AddOrUpdate(er1, er2, er3, er4, er5, er6, er7, er8); LeaveReason lr1 = new LeaveReason() { leaveReasonName = "Holiday", CreateDate = DateTime.Now }; LeaveReason lr2 = new LeaveReason() { leaveReasonName = "Sickness", CreateDate = DateTime.Now }; LeaveReason lr3 = new LeaveReason() { leaveReasonName = "Other reasons", CreateDate = DateTime.Now }; db.LeaveReasons.AddOrUpdate(lr1, lr2, lr3); RequestStatus rs1 = new RequestStatus() { requestStatusName = "Pending", CreateDate = DateTime.Now }; RequestStatus rs2 = new RequestStatus() { requestStatusName = "Approved", CreateDate = DateTime.Now }; RequestStatus rs3 = new RequestStatus() { requestStatusName = "Denied", CreateDate = DateTime.Now }; db.RequestStatus.AddOrUpdate(rs1, rs2, rs3); LeaveRequest leaveRequest1 = new LeaveRequest { allDayEvent = true, deliveryManager = e3, deliveryManagerComment = "", departmentManager = e6, deliveryManagerStatus = rs2, departmentManagerStatus = rs1, departmentManagerComment = "", Description = "My wifes birthday", employee = e1, endTime = new DateTime(2012, 12, 12), leaveReason = lr1, startTime = new DateTime(2012, 12, 22), CreateDate = DateTime.Now }; LeaveRequest leaveRequest2 = new LeaveRequest { allDayEvent = true, deliveryManager = e3, deliveryManagerStatus = rs2, departmentManagerStatus = rs1, deliveryManagerComment = "", departmentManager = e6, departmentManagerComment = "", Description = "My wifes birthday", employee = e1, endTime = new DateTime(2012, 12, 12), leaveReason = lr1, startTime = new DateTime(2012, 12, 22), CreateDate = DateTime.Now }; //db.LeaveRequests.AddOrUpdate(leaveRequest1,leaveRequest2); db.SaveChanges(); }