public static Models.Delegate GetDelegateInfoByDeptId(int deptId) { Models.Delegate del = null; using (SqlConnection conn = new SqlConnection(Data.db_cfg)) { conn.Open(); string sql = @"SELECT * FROM Delegate WHERE deptId=@deptId"; SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.AddWithValue("@deptId", deptId); SqlDataReader reader = cmd.ExecuteReader(); if (reader.Read()) { del = new Models.Delegate { Employee = new Employee { EmpId = (long)reader["empId"] }, Department = new Department { DeptId = (long)reader["deptId"] }, FromDate = (DateTime)reader["fromDate"], ToDate = (DateTime)reader["toDate"] }; } } return(del); }
public ActionResult AddDelegate(string delegateEmp, string from, string to) { if (ModelState.IsValid) { var empNum = Convert.ToInt32(delegateEmp); var newDelegate = _employeeRepo.GetById(empNum); var newDelegateEmailAdd = newDelegate.EmailAddress; var startDate = DateTime.ParseExact(from, "dd/MM/yyyy", CultureInfo.InvariantCulture); var endDate = DateTime.ParseExact(to, "dd/MM/yyyy", CultureInfo.InvariantCulture); var loginUser = Convert.ToInt32(Request.Cookies["Employee"]?["EmpNum"]); var sender = _employeeRepo.GetById(loginUser); var del = new Models.Delegate() { EmpNum = empNum, StartDate = startDate, EndDate = endDate }; _delegateRepo.Add(del); //email to new delegate var emailToNewDelegate = new LUSSISEmail.Builder().From(sender.EmailAddress) .To(newDelegateEmailAdd).ForNewDelegate().Build(); new System.Threading.Thread(delegate() { EmailHelper.SendEmail(emailToNewDelegate); }).Start(); } return(RedirectToAction("MyDelegate")); }
public string DelegateAuthorityOfDepartment(Models.Delegate delegat) { Employee user = AuthUtil.GetCurrentLoggedUser(); if (user == null) { return("Failed"); } delegat.Department = new Department { DeptId = user.DeptId }; long headId = DepartmentService.GetCurrentHead(user.DeptId); DelegateService.AddNewDelegate(delegat, headId); EmailNotification notice = new EmailNotification(); Employee MailReceiver = EmployeeService.GetEmployeeById(delegat.Employee.EmpId); notice.ReceiverMailAddress = MailReceiver.Email; notice.From = delegat.FromDate; notice.To = delegat.ToDate; Task.Run(() => emailService.SendMail(notice, EmailTrigger.ON_DELEGATED_AS_DEPT_HEAD)); return("Success"); }
//find delegate by ID public Models.Delegate findDelegationById(int id) { Models.Delegate d = new Models.Delegate(); List <Models.Delegate> dlist = context.Delegates.Where(x => x.delegateID == id).ToList(); if (dlist.Count() > 0) { d = dlist.First(); } return(d); }
public void addDelegate(string selectedStaff, DateTime startDate, DateTime endDate) { Models.Delegate delegateItem = new Models.Delegate(); delegateItem.staffID = selectedStaff; delegateItem.startDate = startDate; delegateItem.endDate = endDate; delegateItem.status = "active"; context.Delegates.Add(delegateItem); context.SaveChanges(); }
public IHttpActionResult ChangeDelegateState(string userName, string trustedUserName, DelegateStatus state) { try { if (userName == null || userName.Length == 0 || trustedUserName == null || trustedUserName.Length == 0) { return(BadRequest("The supplied username(s) are invalid")); } else { Models.Delegate delegates = db.Delegates.Where(d => (d.UserName == userName && d.TrustedUser == trustedUserName) || (d.TrustedUser == userName && d.UserName == trustedUserName)).FirstOrDefault(); if (delegates == null) { return(BadRequest("The trusted zone relationship does not yet exist")); } else if (delegates.Status == DelegateStatus.Rejected) { return(BadRequest("The trusted zone is in rejected state, hence state cannot be changed")); } else if (delegates.Status == DelegateStatus.Accepted && state == DelegateStatus.Pending) { return(BadRequest("The trusted zone is in accepted state, hence can't change back to pending")); } else { delegates.Status = state; db.SaveChanges(); return(Ok()); } } } catch (Exception e) { string sSource; string sLog; sSource = "Smart Printer Service"; sLog = "Application"; if (!EventLog.SourceExists(sSource)) { EventLog.CreateEventSource(sSource, sLog); } string errorMessage = e.Message + "\n\n"; while (e.InnerException != null) { errorMessage += e.InnerException + "\n"; e = e.InnerException; } EventLog.WriteEntry(sSource, errorMessage, EventLogEntryType.Error); return(InternalServerError()); } }
public static bool AfterDate(long deptId) { DateTime now = System.DateTime.Now; Models.Delegate d = DelegateDAO.GetDelegateByDept(deptId); if (now >= d.ToDate) { return(true); } else { return(false); } }
public IHttpActionResult AddNewDelegate(string userName, string trustedUserName) { try { if (userName == null || userName.Length == 0 || trustedUserName == null || trustedUserName.Length == 0) { return(BadRequest("The supplied username(s) are invalid")); } else { Models.Delegate delegates = db.Delegates.Where(d => (d.UserName == userName && d.TrustedUser == trustedUserName) || (d.TrustedUser == userName && d.UserName == trustedUserName)).FirstOrDefault(); if (delegates != null) { return(BadRequest("The two users are already in the same trusted zone")); } else { db.Delegates.Add(new Models.Delegate() { UserName = userName, TrustedUser = trustedUserName, Status = DelegateStatus.Pending }); db.SaveChanges(); return(Ok()); } } } catch (Exception e) { string sSource; string sLog; sSource = "Smart Printer Service"; sLog = "Application"; if (!EventLog.SourceExists(sSource)) { EventLog.CreateEventSource(sSource, sLog); } string errorMessage = e.Message + "\n\n"; while (e.InnerException != null) { errorMessage += e.InnerException + "\n"; e = e.InnerException; } EventLog.WriteEntry(sSource, errorMessage, EventLogEntryType.Error); return(InternalServerError()); } }
public static void InsertNewDelegate(Models.Delegate d) { using (SqlConnection conn = new SqlConnection(Data.db_cfg)) { conn.Open(); string q = @"INSERT INTO Delegate (empId,deptId,fromDate,toDate)" + "VALUES (@empId, @deptId, @fromDate,@toDate)"; Console.WriteLine(q); SqlCommand cmd = new SqlCommand(q, conn); cmd.Parameters.AddWithValue("@empId", d.Employee.EmpId); cmd.Parameters.AddWithValue("@deptId", d.Department.DeptId); cmd.Parameters.AddWithValue("@fromDate", d.FromDate); cmd.Parameters.AddWithValue("@toDate", d.ToDate); cmd.ExecuteNonQuery(); } }
public void terminateDelegate(Models.Delegate delegateItem) { if (delegateItem.status == "active") { delegateItem.status = "cancelled"; } else { delegateItem.status = "terminated"; string currentHeadID = delegateItem.DeptStaff.Department.headStaffID; DeptStaff currendHead = context.DeptStaffs.Where(x => x.staffID == currentHeadID).First(); currendHead.role = "outOfOfficeHead"; DeptStaff employee = context.DeptStaffs.Where(x => x.staffID == delegateItem.staffID).ToList().First(); employee.role = "emp"; } context.SaveChanges(); }
public IHttpActionResult AssignProxy(string userName, string fileName, string proxyUserName) { try { if (userName == null || userName.Length == 0 || fileName == null || fileName.Length == 0) { return(BadRequest("Incorrect username or filename provided")); } PrintJob printJob = db.PrintJobs.Where(p => p.UserName == userName && p.FileName == fileName).FirstOrDefault(); if (printJob == null) { return(BadRequest("Incorrect username or filename provided. No corresponding printjob exists.")); } Models.Delegate delegateRecord = db.Delegates.Where(d => (d.UserName == userName && d.TrustedUser == proxyUserName) || (d.UserName == proxyUserName && d.TrustedUser == userName)).FirstOrDefault(); if (delegateRecord == null) { return(BadRequest("The assigned proxy is not in the trusted zone of the user. Please add to trusted zone and try again")); } printJob.DelegatedTo = proxyUserName; db.SaveChanges(); return(Ok()); } catch (Exception e) { string sSource; string sLog; sSource = "Smart Printer Service"; sLog = "Application"; if (!EventLog.SourceExists(sSource)) { EventLog.CreateEventSource(sSource, sLog); } string errorMessage = e.Message + "\n\n"; while (e.InnerException != null) { errorMessage += e.InnerException + "\n"; e = e.InnerException; } EventLog.WriteEntry(sSource, errorMessage, EventLogEntryType.Error); return(InternalServerError()); } }
public Dictionary <string, object> GetDelegateInfoOfDepartment() { Dictionary <string, object> resDict = new Dictionary <string, object>(); Employee user = AuthUtil.GetCurrentLoggedUser(); if (user == null) { resDict.Add("auth", false); return(resDict); } resDict.Add("auth", true); Models.Delegate del = DelegateDAO.GetDelegateInfoByDeptId((int)user.DeptId); resDict.Add("delegated", (del != null)); resDict.Add("userInfo", del); return(resDict); }
protected void terminate_button_Click(object sender, EventArgs e) { if (GridView_dHistory.SelectedIndex != -1) { int dID = Convert.ToInt32(GridView_dHistory.SelectedRow.Cells[1].Text.ToString()); Models.Delegate delegateItem = delegateDAO.findDelegationById(dID); if (delegateItem.status == "active" || delegateItem.status == "On delegation") { delegateDAO.terminateDelegate(delegateItem); bindData(deptID); ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script>win.alert('Notice', 'Successful!');</script>"); } else { ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script>win.alert('Notice', 'This delegation is already inactive!');</script>"); } } else { ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script>win.alert('Notice', 'Please select at least one delegation!');</script>"); } }
public static Models.Delegate GetDelegateByDept(long deptId) { Models.Delegate d = new Models.Delegate(); using (SqlConnection conn = new SqlConnection(Data.db_cfg)) { conn.Open(); string q = @"SELECT * from Delegate where deptId =@depId"; SqlCommand cmd = new SqlCommand(q, conn); cmd.Parameters.AddWithValue("@depId", deptId); SqlDataReader reader = cmd.ExecuteReader(); if (reader.Read()) { d = new Models.Delegate() { FromDate = (DateTime)reader["fromDate"], ToDate = (DateTime)reader["toDate"] }; } return(d); } }
public ActionResult ViewDelegate(Models.Delegate d, string delegatedhead, string sessionId) { Employee emp = EmployeeService.GetUserBySessionId(sessionId); long deptId = emp.DeptId; List <Employee> employees = RepresentativeService.GetEmployeesByDepartment(deptId); long headId = DepartmentService.GetCurrentHead(deptId); Employee e = EmployeeDAO.GetEmployeeById(headId); ViewData["currentHead"] = e; ViewData["employees"] = employees; ViewData["timeErr"] = false; bool all = DelegateService.CheckPreviousHeadForNav(deptId); ViewData["all"] = all; ViewData["sessionId"] = sessionId; if (delegatedhead == null && d.Employee == null) { if (DelegateService.CheckDelegatedByDept(deptId)) { ViewData["delegated"] = true; } else { ViewData["delegated"] = false; } return(View()); } else if (delegatedhead == null && d.Employee != null) { d.Department = new Department(); d.Department.DeptId = deptId; bool isThereDelegate = DelegateService.CheckDelegatedByDept(deptId); bool timeErr = (d.FromDate < DateTime.Now && d.ToDate < DateTime.Now); ViewData["timeErr"] = timeErr; if (!isThereDelegate && !timeErr) { DelegateService.AddNewDelegate(d, headId); EmailNotification notice = new EmailNotification(); Employee MailReceiver = EmployeeService.GetEmployeeById(d.Employee.EmpId); notice.ReceiverMailAddress = MailReceiver.Email; notice.From = d.FromDate; notice.To = d.ToDate; Task.Run(() => emailService.SendMail(notice, EmailTrigger.ON_DELEGATED_AS_DEPT_HEAD)); } bool allnav = DelegateService.CheckPreviousHeadForNav(deptId); ViewData["all"] = allnav; long head = DepartmentService.GetCurrentHead(deptId); Employee h = EmployeeDAO.GetEmployeeById(head); ViewData["currentHead"] = h; if (timeErr) { ViewData["delegated"] = false; } else { ViewData["delegated"] = true; } return(View()); } else if (delegatedhead != null && d.Employee == null) { EmailNotification notice = new EmailNotification(); long head = DepartmentService.GetCurrentHead(deptId); Employee MailReceiver = EmployeeDAO.GetEmployeeById(head); notice.ReceiverMailAddress = MailReceiver.Email; DelegateService.DelegateToPreviousHead(deptId); Task.Run(() => emailService.SendMail(notice, EmailTrigger.ON_REMOVED_DEPT_HEAD)); List <Employee> emps = RepresentativeService.GetEmployeesByDepartment(deptId); ViewData["employees"] = emps; ViewData["delegated"] = false; bool show = DelegateService.CheckPreviousHeadForNav(deptId); ViewData["all"] = show; return(View()); } else { ViewData["delegated"] = false; return(View()); } }
public static void AddNewDelegate(Models.Delegate d, long currentHead) { DelegateDAO.InsertNewDelegate(d); EmployeeDAO.UpdateEmployeeHead(d.Employee.EmpId, currentHead); DepartmentDAO.UpdateDepartmentHead(d.Department.DeptId, d.Employee.EmpId); }