/* * Logs the user into the system. * * Takes username and password in * If the username and password is valid, this generates a token for the employee * This token is stored into the database for validation when using in other methods. */ public WCF_Employee Login(string username, string password) { WCF_Employee wcfEmployee = null; // If login succeeds, fetch the token, otherwise, return null // Validate username and password if (Membership.ValidateUser(username, password)) { // Fetch or generate token var context = new LogicUniversityEntities(); var query = from x in context.employees where x.user_id == username select x; var result = query.ToList(); if (query.Any()) { // Generate a token for the resulting employee. String token = GenerateToken(); // Store token in database var first = result.First(); first.token = token; System.Diagnostics.Debug.WriteLine(context.SaveChanges()); // Pass the token to the service consumer wcfEmployee = new WCF_Employee(first.employee_id, first.employee_name, first.email_id, username, first.department_id, first.supervisor_id, token, Roles.GetRolesForUser(username).FirstOrDefault()); } } // Return the token to user return(wcfEmployee); }
protected void LoadROGraph(string selectedDepartment, DateTime From, DateTime To) { List <string> departmentcode = new List <string>(); var context = new LogicUniversityEntities(); var result = context.requisition_order.Where(x => (x.requisition_status == "Approved") && (x.requisition_date >= From) && (x.requisition_date <= To)).ToList(); foreach (requisition_order dept in result) { departmentcode.Add(dept.requisition_id.Substring(0, 4)); } var query = departmentcode.GroupBy(s => s).Select(g => new { Dept = g.Key, Count = g.Count() }); Series series = getROBasedDepartmentAndTime.Series["Series1"]; Departments.ClearSelection(); foreach (var r in query) { if ((r.Count != 0) && (selectedDepartment.Contains(r.Dept))) { Departments.Items.FindByValue(r.Dept).Selected = true; series.Points.AddXY(r.Dept, r.Count); } } if (getROBasedDepartmentAndTime != null) { ErrorMSg.Visible = false; } else { ErrorMSg.Text = "Please make other selection"; } }
/* Service methods =========================================*/ // Fetches an employee by using a token. public WCF_Employee GetEmployeeByToken(String token) { if (AuthenticateToken(token)) { var context = new LogicUniversityEntities(); var query = from x in context.employees where x.token == token select x; // If there exists the token for a user, create a wcf employee and return it if (query.Count() != 0) { var first = query.First(); String role = null; role = Roles.GetRolesForUser(first.user_id).FirstOrDefault(); return(new WCF_Employee(first.employee_id, first.employee_name, first.email_id, first.user_id, first.department_id, first.supervisor_id, first.token, role)); } else { return(null); } } return(null); }
public List <WCF_RequestQuantityByDepartment> getRequisitionQuantityByDepartmentWithinTime(String startParam, String endParam) { List <WCF_RequestQuantityByDepartment> wcfList = new List <WCF_RequestQuantityByDepartment>(); string format = "dd-MM-yyyy"; CultureInfo provider = CultureInfo.InvariantCulture; DateTime start = DateTime.ParseExact(startParam, format, provider); DateTime end = DateTime.ParseExact(endParam, format, provider); var context = new LogicUniversityEntities(); var query = (from dept in context.departments join emp in context.employees on dept.department_id equals emp.department_id join req in context.requisition_order on emp.employee_id equals req.employee_id join reqDetails in context.requisition_order_detail on req.requisition_id equals reqDetails.requisition_id join inv in context.inventories on reqDetails.item_number equals inv.item_number where req.requisition_date.CompareTo(start) >= 0 && req.requisition_date.CompareTo(end) <= 0 select new { dept, emp, req, reqDetails, inv }); var result = query.GroupBy(d => d.dept.department_id) .Select(g => new { DepartmentId = g.Key.Trim(), ItemQuantity = g.Sum(x => x.reqDetails.item_requisition_quantity) }); // String returnString = ""; foreach (var i in result) { //returnString = returnString + i; wcfList.Add(new WCF_RequestQuantityByDepartment(i.DepartmentId, i.ItemQuantity)); } return(wcfList); }
public List <WCF_PurchaseQuantityByItemCategory> getPurchaseQuantityByItemCategoryWithMonthsBack(string startParam, string endParam) { List <WCF_PurchaseQuantityByItemCategory> wcfList = new List <WCF_PurchaseQuantityByItemCategory>(); // Debugger test string format = "dd-MM-yyyy"; CultureInfo provider = CultureInfo.InvariantCulture; DateTime start = DateTime.ParseExact(startParam, format, provider); DateTime end = DateTime.ParseExact(endParam, format, provider); var context = new LogicUniversityEntities(); var query = from po in context.purchase_order join pod in context.purchase_order_detail on po.purchase_order_number equals pod.purchase_order_number join inv in context.inventories on pod.item_number equals inv.item_number where (pod.item_purchase_order_status.Trim() == "Completed" || pod.item_purchase_order_status.Trim() == "Pending") && (po.purchase_order_date.CompareTo(end) <= 0 && po.purchase_order_date.CompareTo(start) >= 0) select new { po, pod, inv }; // Query is definitely working fine. var result = query.GroupBy(cat => cat.inv.category) .Select(g => new { Category = g.Key.Trim(), PurchaseQuantity = g.Sum(x => x.pod.item_purchase_order_quantity) }); foreach (var i in result.ToList()) { wcfList.Add(new WCF_PurchaseQuantityByItemCategory(i.Category.Trim(), i.PurchaseQuantity)); } return(wcfList); }
protected void Page_Load(object sender, EventArgs e) { var context = new LogicUniversityEntities(); var recentRequisitionOrders = context.getLowStockItemsByCategory(); LowStockItemGridView.DataSource = recentRequisitionOrders.ToList(); LowStockItemGridView.DataBind(); }
// Logs the user out /* * Doing this will clear the token in the database for the employee, if it exists. */ public string Logout(string token) { var context = new LogicUniversityEntities(); var query = from x in context.employees where x.token == token select x; var result = query.First(); result.token = null; context.SaveChanges(); return("done"); }
public List <WCF_RequestQuantityByDepartment> getRequisitionQuantityByDepartment() { List <WCF_RequestQuantityByDepartment> wcfList = new List <WCF_RequestQuantityByDepartment>(); var context = new LogicUniversityEntities(); var result = context.getRequisitionQuantityByDepartment(); foreach (var i in result.ToList()) { wcfList.Add(new WCF_RequestQuantityByDepartment(i.department_id.Trim(), i.item_request_quantity)); } return(wcfList); }
public List <WCF_Item> GetInventory() { var context = new LogicUniversityEntities(); var query = from x in context.inventories select x; List <inventory> inventories = query.ToList(); List <WCF_Item> wcf_items = new List <WCF_Item>(); foreach (inventory i in inventories) { wcf_items.Add(new WCF_Item(i.item_number, i.description, i.category, i.unit_of_measurement, i.item_status)); } return(wcf_items); }
public List <WCF_MegaObject> getPendingPurchaseOrderCountBySupplier() { List <WCF_MegaObject> wcfList = new List <WCF_MegaObject>(); var context = new LogicUniversityEntities(); var result = context.getPendingPurchaseOrderCountBySupplier(); foreach (var i in result.ToList()) { wcfList.Add(new WCF_MegaObject(i.SupplierId.Trim(), i.PendingPurchaseOrderQuantity)); } return(wcfList); }
public List <WCF_Item> getLowStockItemsByCategory() { List <WCF_Item> wcfList = new List <WCF_Item>(); var context = new LogicUniversityEntities(); var result = context.getLowStockItemsByCategory(); foreach (var i in result.ToList()) { wcfList.Add(new WCF_Item(i.item_number, i.description, i.current_quantity, i.reorder_level)); } return(wcfList); }
/* Token methods ===========================*/ // Authenticates a token // Returns true if token exists in employee table // Returns false if token doesn't exist in employee table protected bool AuthenticateToken(String token) { var context = new LogicUniversityEntities(); var query = from x in context.employees where x.token == token select x; if (query.Count() != 0) { return(true); } else { return(false); } }
public List <WCF_Department> GetDepartments() { var context = new LogicUniversityEntities(); var query = from x in context.departments select x; List <department> departments = query.ToList(); List <WCF_Department> wcf_departments = new List <WCF_Department>(); foreach (department d in departments) { WCF_Department wcf_d = new WCF_Department(d.department_id, d.head_id, d.temp_head_id, d.department_pin, d.department_name, d.contact_name, d.phone_number, d.fax_number); wcf_departments.Add(wcf_d); } return(wcf_departments); }
public List <WCF_RequisitionOrder> GetRequisitionOrders(string dept) { var context = new LogicUniversityEntities(); var query = from x in context.requisition_order where x.requisition_id.Substring(0, 4) == dept select x; List <requisition_order> requisitionOrders = query.ToList(); List <WCF_RequisitionOrder> wcf_requisitionOrders = new List <WCF_RequisitionOrder>(); foreach (requisition_order ro in requisitionOrders) { WCF_RequisitionOrder wcf_ro = new WCF_RequisitionOrder(ro.requisition_id.Trim(), ro.employee_id, ro.requisition_status, ro.requisition_date); wcf_requisitionOrders.Add(wcf_ro); } return(wcf_requisitionOrders); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { var context = new LogicUniversityEntities(); Departments.DataSource = context.departments.Where(x => x.department_id != "STOR").Select(x => new { x.department_name, x.department_id }).ToList(); Departments.DataTextField = "department_name"; Departments.DataValueField = "department_id"; Departments.DataBind(); foreach (ListItem chkitem in Departments.Items) { chkitem.Selected = true; } ChangeROGraph(); } }
public List <WCF_PurchaseOrder> GetPurchaseOrders() { var context = new LogicUniversityEntities(); var query = from p in context.purchase_order join d in context.purchase_order_detail on p.purchase_order_number equals d.purchase_order_number join i in context.inventories on d.item_number equals i.item_number select new { p, d, i }; var purchaseOrders = query.ToList(); List <WCF_PurchaseOrder> wcf_purchaseOrders = new List <WCF_PurchaseOrder>(); foreach (var i in purchaseOrders) { wcf_purchaseOrders.Add(new WCF_PurchaseOrder(i.p.purchase_order_number, i.i.item_number, i.i.category, i.d.item_purchase_order_quantity, i.d.item_accept_quantity, i.i.item_status)); } return(wcf_purchaseOrders); }
protected void ChangeROGraph() { List <string> departmentcode = new List <string>(); var context = new LogicUniversityEntities(); var result = context.requisition_order.Where(x => (x.requisition_status == "Approved")).ToList(); foreach (requisition_order dept in result) { departmentcode.Add(dept.requisition_id.Substring(0, 4)); } var query = departmentcode.GroupBy(s => s).Select(g => new { Dept = g.Key, Count = g.Count() }); Series series = getROBasedDepartmentAndTime.Series["Series1"]; foreach (var r in query) { series.Points.AddXY(r.Dept, r.Count); } }