//SendReportEmail(int empId, List<ReportItem> reportItemList) public static bool SendReportEmail(int empId, List <ReportItemVM> reportItemList) { using (SA46Team08ADProjectContext entities = new SA46Team08ADProjectContext()) { try { var to_email = entities.Employees.Where(e => e.EmpId == empId).Select(e => e.EmpEmail).First(); var _to = entities.Employees.Where(e => e.EmpId == empId).Select(e => e.EmpName).First(); var deptCode = entities.Employees.Where(e => e.EmpId == empId).Select(e => e.DeptCode).First(); var head_id = entities.Departments.Where(d => d.DeptCode == deptCode).Select(d => d.DeptHeadId).First(); var dept_head_email = entities.Employees.Where(e => e.EmpId == head_id).Select(e => e.EmpEmail).First(); string type = "Representative Assignment"; string content = "You have been assigned as representative for your department by your department head"; MailMessage msg = new MailMessage(); msg.From = new MailAddress(dept_head_email); msg.To.Add(to_email); msg.Subject = type; msg.IsBodyHtml = false; msg.Body = "Hi" + " " + _to + "," + Environment.NewLine + Environment.NewLine + content + Environment.NewLine + Environment.NewLine + "Thank you."; msg.Priority = MailPriority.High; SmtpClient client = new SmtpClient(); client.Send(msg); return(true); } catch (Exception ex) { throw ex; } } }
public static bool AddNewEmailToEmp(int empId, string type, string content) { using (SA46Team08ADProjectContext entities = new SA46Team08ADProjectContext()) { try { var from_email = entities.Employees.Where(e => e.EmpId == empId).Select(e => e.EmpEmail).First(); var to_email = entities.Employees.Where(e => e.EmpId == empId).Select(e => e.EmpEmail).First(); var _to = entities.Employees.Where(e => e.EmpId == empId).Select(e => e.EmpName).First(); MailMessage msg = new MailMessage(); msg.From = new MailAddress(from_email); msg.To.Add(to_email); msg.Subject = type; msg.IsBodyHtml = false; msg.Body = "Hi" + " " + _to + "," + Environment.NewLine + Environment.NewLine + content + Environment.NewLine + Environment.NewLine + "Thank you."; msg.Priority = MailPriority.High; SmtpClient client = new SmtpClient(); client.Send(msg); return(true); } catch (Exception ex) { throw ex; } } }
//SendLowStockEmail //with attach public static bool SendLowStockEmail(int empId, string attachfile) { using (SA46Team08ADProjectContext entities = new SA46Team08ADProjectContext()) { try { var from_email = entities.Employees.Where(e => e.EmpId == empId).Select(e => e.EmpEmail).First(); var to_email = entities.Employees.Where(e => e.EmpId == 101).Select(e => e.EmpEmail).First(); var _to = entities.Employees.Where(e => e.EmpId == 101).Select(e => e.EmpName).First(); var date = DateTime.Now.ToString("dd MMMM yyyy h:mm tt"); string type = "Low Stock"; string content = "You have recently requested for a low stock item report for the Logic University on"; string filePath = HttpContext.Current.Server.MapPath("~/PDF/"); MailMessage msg = new MailMessage(); msg.From = new MailAddress(from_email); msg.To.Add(to_email);//101's email msg.Subject = type; msg.IsBodyHtml = false; msg.Body = "Hi" + " " + _to + "," + Environment.NewLine + Environment.NewLine + content + " " + date + Environment.NewLine + Environment.NewLine + "Kindly refer to the attachment." + Environment.NewLine + Environment.NewLine + "Thank you."; Attachment at = new Attachment(filePath + attachfile); msg.Attachments.Add(at); msg.Priority = MailPriority.High; SmtpClient client = new SmtpClient(); client.Send(msg); return(true); } catch (Exception ex) { throw ex; } } }
//SendAdjReqEmail(int empId, List<Adjustment> adjList) public static bool SendAdjReqEmail(int empId, List <AdjustmentVM> adjList) { using (SA46Team08ADProjectContext entities = new SA46Team08ADProjectContext()) { try { var from_email = entities.Employees.Where(e => e.EmpId == empId).Select(e => e.EmpEmail).First(); var to_email = entities.Employees.Where(e => e.EmpId == 105).Select(e => e.EmpEmail).First(); var _to = entities.Employees.Where(e => e.EmpId == 105).Select(e => e.EmpName).First(); string voucherNo = adjList.Select(a => a.VoucherNo).First().ToString(); string type = "Adjustment Request"; string content = "has been raised."; MailMessage msg = new MailMessage(); msg.From = new MailAddress(from_email); msg.To.Add(to_email); msg.Subject = type; msg.IsBodyHtml = false; msg.Body = "Hi" + " " + _to + "," + Environment.NewLine + Environment.NewLine + voucherNo + " " + content + Environment.NewLine + Environment.NewLine + "Thank you."; msg.Priority = MailPriority.High; SmtpClient client = new SmtpClient(); client.Send(msg); return(true); } catch (Exception ex) { throw ex; } } }
// add an adjustment // done public static List <AdjustmentVM> AddAdj(List <AdjustmentVM> adjList) { using (SA46Team08ADProjectContext entities = new SA46Team08ADProjectContext()) { try { string voucherNo = GenerateVoucherNo(); for (int i = 0; i < adjList.Count; i++) { Adjustment adj = new Adjustment(); adj.VoucherNo = voucherNo; adjList[i].VoucherNo = voucherNo; adj.EmpId = adjList[i].EmpId; adj.DateTimeIssued = adjList[i].DateTimeIssued; adj.ItemCode = adjList[i].ItemCode; adj.Reason = adjList[i].Reason; adj.QtyChange = adjList[i].QtyChange; adj.Status = adjList[i].Status; adj.ApproverId = adjList[i].ApproverId; adj.ApproverComment = adjList[i].ApproverComment; entities.Adjustments.Add(adj); entities.SaveChanges(); } return(adjList); } catch (Exception ex) { throw ex; } } }
//AddFulfillNotification with empId and repId public static void AddFulfillNotification(int empId, int repId) { using (SA46Team08ADProjectContext entities = new SA46Team08ADProjectContext()) { var emploeeses = entities.Employees.Where(n => n.EmpId == empId).FirstOrDefault(); if (emploeeses != null) { //var request = entities.Notifications.Where(n => n.Employee.Department.DeptRepId == repId).FirstOrDefault(); //if (request != null) //{ Notification noti = new Notification(); noti.FromEmp = empId; noti.ToEmp = repId; noti.NotificationDateTime = System.DateTime.Now; noti.RouteUri = ""; noti.Type = "Request Submitted"; noti.Content = "Request Submitted"; noti.IsRead = true; entities.Notifications.Add(noti); entities.SaveChanges(); //} } } }
//AddLowStkNotification with empId and item public static void AddLowStkNotification(int empId, Item i) { using (SA46Team08ADProjectContext entities = new SA46Team08ADProjectContext()) { try { Notification noti = new Notification(); noti.FromEmp = empId; noti.ToEmp = 104; noti.NotificationDateTime = System.DateTime.Now; noti.RouteUri = ""; noti.Type = "Low Stock"; noti.Content = "In a recent stationery request disbursement, there are some items with balance below reorder level. "; noti.IsRead = true; entities.Notifications.Add(noti); entities.SaveChanges(); } catch (Exception ex) { throw ex; } //var lowStkNoti = entities.Notifications.Where(n => n.Employee.EmpId == empId).FirstOrDefault(); //if (lowStkNoti != null) //{ // lowStkNoti.Employee.EmpId = empId; // Item item = i; // entities.Notifications.Add(lowStkNoti); // entities.SaveChanges(); //} } }
// add a transaction // done public static TransactionVM AddTran(TransactionVM t) { using (SA46Team08ADProjectContext entities = new SA46Team08ADProjectContext()) { try { Transaction tran = new Transaction(); tran.TranDateTime = t.TranDateTime; tran.ItemCode = t.ItemCode; tran.QtyChange = t.QtyChange; tran.UnitPrice = t.UnitPrice; tran.Desc = t.Desc; tran.DeptCode = t.DeptCode; tran.SuppCode = t.SuppCode; tran.VoucherNo = t.VoucherNo; entities.Transactions.Add(tran); entities.SaveChanges(); List <Transaction> translist = entities.Transactions.ToList(); int transId = translist[translist.Count - 1].TranId; t.TranId = transId; return(t); } catch (Exception ex) { throw ex; } } }
//add RequestDetail with reqId and reqDet public static RequestDetailVM AddReqDet(int reqId, RequestDetailVM reqDet) { RequestDetailVM request = new RequestDetailVM(); using (SA46Team08ADProjectContext entities = new SA46Team08ADProjectContext()) { RequestDetail req = new RequestDetail(); req.ReqId = reqId; request.ReqId = req.ReqId; List <RequestDetail> rd = entities.RequestDetails.Where(x => x.ReqId == reqId).ToList(); if (rd.Count == 0) { req.ReqLineNo = 1; } else { req.ReqLineNo = rd[rd.Count - 1].ReqLineNo + 1; } request.ReqLineNo = req.ReqLineNo; req.ItemCode = reqDet.ItemCode; request.ItemCode = req.ItemCode; req.ReqQty = reqDet.ReqQty; request.ReqQty = req.ReqQty; req.AwaitQty = reqDet.AwaitQty; request.AwaitQty = req.AwaitQty; req.FulfilledQty = reqDet.FulfilledQty; request.FulfilledQty = req.FulfilledQty; entities.RequestDetails.Add(req); entities.SaveChanges(); } return(request); }
//getDept by empId public static DepartmentVM GetDept(int empId) { DepartmentVM department = new DepartmentVM(); using (SA46Team08ADProjectContext entities = new SA46Team08ADProjectContext()) { string deptCode = EmployeeBL.GetDeptCode(empId); department = entities.Departments.Where(d => d.DeptCode.Equals(deptCode)) .Select(d => new DepartmentVM() { DeptCode = d.DeptCode, DeptName = d.DeptName, DeptCtcNo = d.DeptCtcNo, DeptFaxNo = d.DeptFaxNo, ColPtId = d.ColPtId, DeptHeadId = d.DeptHeadId, DeptRepId = d.DeptRepId, DelegateApproverId = d.DelegateApproverId, DelegateFromDate = d.DelegateFromDate, DelegateToDate = d.DelegateToDate, EmpId = empId }).First <DepartmentVM>(); } return(department); }
//set Delegate by DepartmentCode , fromDate , toDate and empId public static bool setDelegate(string deptCode, DateTime fromDate, DateTime toDate, int empId) { //DepartmentVM deptVM = new DepartmentVM(); using (SA46Team08ADProjectContext entities = new SA46Team08ADProjectContext()) { Department department = entities.Departments.Where(d => d.DeptCode.Equals(deptCode)).First(); department.DeptCode = deptCode; department.DelegateFromDate = fromDate; department.DelegateToDate = toDate; department.DelegateApproverId = empId; int rowinserted = entities.SaveChanges(); if (rowinserted > 0) { string startDate = (department.DelegateFromDate ?? default(DateTime)).ToString("dd MMMM yyyy"); string endDate = (department.DelegateToDate ?? default(DateTime)).ToString("dd MMMM yyyy"); EmailBL.AddNewEmailToEmp(empId, "Assign Delegate", "You have been assigned as delegate from " + startDate + " to " + endDate); return(true); } else { return(false); } } }
// remove request by empId and status // done public static bool RemoveReq(int empId, string status) { using (SA46Team08ADProjectContext entities = new SA46Team08ADProjectContext()) { try { List <Request> reqlist = entities.Requests.Where(r => r.EmpId == empId && r.Status == status).ToList(); if (reqlist.Count > 0) { for (int i = 0; i < reqlist.Count; i++) { if (reqlist[i].Status.Equals("Unsubmitted") || reqlist[i].Status.Equals("Bookmarked")) { RequestDetailBL.removeAllReqDet(reqlist[i].ReqId); } else { reqlist[i].Status = "Cancelled"; reqlist[i].CancelledDateTime = DateTime.Now; entities.SaveChanges(); } } } return(true); } catch (Exception ex) { throw ex; } } }
//AddAcptNotification with repId public static bool AddAcptNotification(int repId) { using (SA46Team08ADProjectContext entities = new SA46Team08ADProjectContext()) { try { Notification noti = new Notification(); noti.FromEmp = 104; noti.ToEmp = repId; noti.NotificationDateTime = System.DateTime.Now; noti.RouteUri = ""; noti.Type = "Request Submitted"; noti.Content = "Request Submitted"; noti.IsRead = true; entities.Notifications.Add(noti); int rowinserted = entities.SaveChanges(); if (rowinserted > 0) { return(true); } else { return(false); } } catch (Exception ex) { throw ex; } } }
//update RequestDetail with reqId and reqDet public static RequestDetailVM UpdateReqDet(int reqId, RequestDetailVM reqDet) { RequestDetailVM ReqDetailVM = new RequestDetailVM(); using (SA46Team08ADProjectContext entities = new SA46Team08ADProjectContext()) { RequestDetail updateReqDetail = entities.RequestDetails.Where(r => r.ReqId == reqId && r.ItemCode.Equals(reqDet.ItemCode)).First(); updateReqDetail.ReqId = reqId; updateReqDetail.ItemCode = reqDet.ItemCode; updateReqDetail.ReqQty = reqDet.ReqQty; updateReqDetail.AwaitQty = reqDet.AwaitQty; updateReqDetail.FulfilledQty = reqDet.FulfilledQty; entities.SaveChanges(); List <RequestDetail> lst = entities.RequestDetails.ToList(); RequestDetail rd = lst[lst.Count - 1]; ReqDetailVM.ReqId = rd.ReqId; ReqDetailVM.ItemCode = rd.ItemCode; ReqDetailVM.ReqQty = rd.ReqQty; ReqDetailVM.AwaitQty = rd.AwaitQty; ReqDetailVM.FulfilledQty = rd.FulfilledQty; } return(ReqDetailVM); }
// update request // done public static RequestVM UpdateReq(RequestVM req) { using (SA46Team08ADProjectContext entities = new SA46Team08ADProjectContext()) { int reqId = req.ReqId; Request request = entities.Requests.Where(r => r.ReqId == reqId).FirstOrDefault(); request.ApproverComment = req.ApproverComment; if (req.ReqDateTime != null && DateTime.Compare(req.ReqDateTime, new DateTime(1800, 01, 01)) > 0) { request.ReqDateTime = req.ReqDateTime; } if (req.ApprovedDateTime != null && DateTime.Compare(req.ApprovedDateTime, new DateTime(1800, 01, 01)) > 0) { request.ApprovedDateTime = req.ApprovedDateTime; } if (req.CancelledDateTime != null && DateTime.Compare(req.CancelledDateTime, new DateTime(1800, 01, 01)) > 0) { request.CancelledDateTime = req.CancelledDateTime; } if (req.FulfilledDateTime != null && DateTime.Compare(req.FulfilledDateTime, new DateTime(1800, 01, 01)) > 0) { request.FulfilledDateTime = req.FulfilledDateTime; } request.Status = req.Status; entities.SaveChanges(); } return(req); }
// submit request // done public static RequestVM SubmitReq(int reqId, List <RequestDetailVM> reqDetList) { // make requestId in reqDetList is the same as reqId using (SA46Team08ADProjectContext entities = new SA46Team08ADProjectContext()) { try { RequestVM req = GetReq(reqId); for (int i = 0; i < reqDetList.Count; i++) { if (reqDetList[i].ReqId == reqId) { List <RequestDetail> rdlist = entities.RequestDetails.ToList(); for (int j = 0; j < rdlist.Count; j++) { if (reqDetList[i].ReqId == rdlist[j].ReqId && reqDetList[i].ReqLineNo == rdlist[j].ReqLineNo) { rdlist[j].ReqQty = reqDetList[i].ReqQty; rdlist[j].AwaitQty = reqDetList[i].AwaitQty; rdlist[j].FulfilledQty = reqDetList[i].FulfilledQty; entities.SaveChanges(); } } } } req.ReqDateTime = DateTime.Now; req.Status = "Submitted"; req = UpdateReq(req); int empId = req.EmpId; Employee emp = entities.Employees.Where(x => x.EmpId == empId).FirstOrDefault(); string deptCode = emp.DeptCode; Department dept = entities.Departments.Where(x => x.DeptCode == deptCode).FirstOrDefault(); int fromEmpId = req.EmpId; int toEmpId; if (dept.DelegateApproverId != null && DateTime.Compare(DateTime.Now, (DateTime)dept.DelegateFromDate) >= 0 && DateTime.Compare(DateTime.Now, (DateTime)dept.DelegateToDate) >= 0) { toEmpId = (int)dept.DelegateApproverId; } else { toEmpId = (int)dept.DeptHeadId; } string type = "Stationery Request"; string content = "A new stationery request has been submitted"; NotificationBL.AddNewNotification(fromEmpId, toEmpId, type, content); // for email EmailBL.SendNewReqEmail(empId, req); return(req); } catch (Exception ex) { throw ex; } } }
// remove request by reqId // done public static bool RemoveReq(int reqId) { using (SA46Team08ADProjectContext entities = new SA46Team08ADProjectContext()) { try { Request request = entities.Requests.Where(r => r.ReqId == reqId).FirstOrDefault(); if (request != null) { if (request.Status.Equals("Unsubmitted") || request.Status.Equals("Bookmarked")) { RequestDetailBL.removeAllReqDet(reqId); } else { request.Status = "Cancelled"; request.CancelledDateTime = DateTime.Now; entities.SaveChanges(); } } return(true); } catch (Exception ex) { throw ex; } } }
//AddFulfillNotification with empId and repId public static bool AddFulfillNotification(int empId, int repId) { using (SA46Team08ADProjectContext entities = new SA46Team08ADProjectContext()) { //var emploeeses=entities.Employees.Where(n => n.EmpId == empId).FirstOrDefault(); //if (emploeeses != null) try { Notification noti = new Notification(); noti.FromEmp = empId; noti.ToEmp = repId; noti.NotificationDateTime = System.DateTime.Now; noti.RouteUri = ""; noti.Type = "Request Submitted"; noti.Content = "Request Submitted"; noti.IsRead = true; entities.Notifications.Add(noti); int rowinserted = entities.SaveChanges(); if (rowinserted > 0) { return(true); } else { return(false); } } catch (Exception ex) { throw ex; } } }
//get employee role by employeeid public static string GetRole(int empId) { using (SA46Team08ADProjectContext entities = new SA46Team08ADProjectContext()) { var role = entities.Employees.Where(e => e.EmpId == empId).Select(e => e.Role).First(); return(role); } }
//get department code by employeeid public static string GetDeptCode(int empId) { using (SA46Team08ADProjectContext entities = new SA46Team08ADProjectContext()) { string deptcode = entities.Employees.Where(e => e.EmpId == empId).Select(e => e.DeptCode).First(); return(deptcode); } }
//GetDeptCode public static string GetDeptCode(RequestDetail reqDet) { using (SA46Team08ADProjectContext entities = new SA46Team08ADProjectContext()) { string deptcode = entities.RequestDetails.Select(r => r.Request.Employee.DeptCode).FirstOrDefault(); return(deptcode); } }
//need to clearify return type and model public static string GetHeadId(int empId) { using (SA46Team08ADProjectContext entities = new SA46Team08ADProjectContext()) { string deptCode = GetDeptCode(empId); string DeptHeadId = entities.Departments.Where(x => x.DeptCode == deptCode).Select(x => x.DeptHeadId).First().ToString(); return(DeptHeadId); } }
//remove All public static void removeAllReqDet(int reqId) { using (SA46Team08ADProjectContext entities = new SA46Team08ADProjectContext()) { RequestDetail request = entities.RequestDetails.Where(r => r.ReqId == reqId).FirstOrDefault(); if (request != null) { entities.RequestDetails.Remove(request); entities.SaveChanges(); } } }
//set CollPt by DepartmentCode , collPt public static void setCollPt(string deptCode, int collPt) { using (SA46Team08ADProjectContext entities = new SA46Team08ADProjectContext()) { Department department = entities.Departments.Where(d => d.DeptCode.Equals(deptCode)).First <Department>(); { department.ColPtId = collPt; entities.SaveChanges(); } } return; }
//update Await public static void UpdateAwait(int reqId, int awaitQty) { using (SA46Team08ADProjectContext entities = new SA46Team08ADProjectContext()) { RequestDetail await = entities.RequestDetails.Where(r => r.ReqId == reqId).First <RequestDetail>(); if (await != null) { await.AwaitQty = awaitQty; } entities.SaveChanges(); } }
// add request // done public static RequestVM AddReq(int empId, string status) { try { RequestVM request = new RequestVM(); using (SA46Team08ADProjectContext entities = new SA46Team08ADProjectContext()) { Request req = new Request(); req.EmpId = empId; req.Status = status; req.ApproverComment = ""; entities.Requests.Add(req); entities.SaveChanges(); List <Request> lst = entities.Requests.ToList(); Request r = lst[lst.Count - 1]; request.ReqId = r.ReqId; request.EmpId = r.EmpId; if (r.ApproverId != null) { request.ApproverId = (int)r.ApproverId; } else { request.ApproverId = 0; } request.ApproverComment = r.ApproverComment; if (r.ReqDateTime != null) { request.ReqDateTime = (DateTime)r.ReqDateTime; } if (r.ApprovedDateTime != null) { request.ApprovedDateTime = (DateTime)r.ApprovedDateTime; } if (r.CancelledDateTime != null) { request.CancelledDateTime = (DateTime)r.CancelledDateTime; } if (r.FulfilledDateTime != null) { request.FulfilledDateTime = (DateTime)r.FulfilledDateTime; } request.Status = r.Status; } return(request); } catch (Exception ex) { throw ex; } }
//set Rep by DepartmentCode , fromEmpId and toEmpId public static void setRep(string deptCode, int empId) { using (SA46Team08ADProjectContext entities = new SA46Team08ADProjectContext()) { Department department = entities.Departments.Where(d => d.DeptCode.Equals(deptCode)).First <Department>(); { department.DeptRepId = empId; entities.SaveChanges(); EmailBL.AddNewEmailToEmp(empId, "Assign Reprsentative", "You have been assigned as reprsentative for your department."); } } return; }
//remove Delegate by DepartmentCode public static void removeDelegate(string deptCode) { using (SA46Team08ADProjectContext entities = new SA46Team08ADProjectContext()) { Department department = entities.Departments.Where(d => d.DeptCode.Equals(deptCode)).First <Department>(); { department.DelegateApproverId = null; department.DelegateFromDate = null; department.DelegateToDate = null; entities.SaveChanges(); }; } }
//Get Employee public static List <EmployeeVM> GetEmplistsbyDeptCode(string deptCode) { List <EmployeeVM> empvmList = new List <EmployeeVM>(); using (SA46Team08ADProjectContext entities = new SA46Team08ADProjectContext()) { List <Employee> empList = entities.Employees.Where(e => e.DeptCode.Equals(deptCode)).ToList(); empvmList = Utility.EmployeeUtility.Convert_Employee_To_EmployeeVM(empList); } return(empvmList); }
//Update Fulfilled public static void UpdateFulfilled(int reqId, int fulfilledQty) { using (SA46Team08ADProjectContext entities = new SA46Team08ADProjectContext()) { RequestDetail fulfilled = entities.RequestDetails.Where(r => r.ReqId == reqId).First <RequestDetail>(); //RequestDetail fulfilled = entities.RequestDetails.Where(r => r.ReqId == reqId).First<RequestDetail>(); if (fulfilled != null) { fulfilled.FulfilledQty = fulfilledQty; entities.SaveChanges(); } } }