public static bool UpdateRequisitionDetail(RequisitionDetail updateRequisitionDetail) { bool result = false; try { LussisEntities context = new LussisEntities(); RequisitionDetail requisitionDetail = context.RequisitionDetails .Where(req => req.ReqNo.Equals(updateRequisitionDetail.ReqNo) && req.ItemNo.Equals(updateRequisitionDetail.ItemNo)).FirstOrDefault(); if (requisitionDetail != null) { requisitionDetail.ReqNo = updateRequisitionDetail.ReqNo; requisitionDetail.ItemNo = updateRequisitionDetail.ItemNo; requisitionDetail.Qty = updateRequisitionDetail.Qty; context.SaveChanges(); result = true; } } catch (Exception) { result = false; } return(result); }
public static bool AddRequisitionDetail(RequisitionDetail addRequisitionDetail) { bool result = false; try { LussisEntities context = new LussisEntities(); RequisitionDetail requisitionDetail = new RequisitionDetail(); requisitionDetail.ReqNo = addRequisitionDetail.ReqNo; requisitionDetail.ItemNo = addRequisitionDetail.ItemNo; requisitionDetail.Qty = addRequisitionDetail.Qty; context.RequisitionDetails.Add(requisitionDetail); context.SaveChanges(); result = true; } catch (Exception) { result = false; } return(result); }
//Update data for detail page public static void UpdateItem(int requisitionNo, string itemNo, int qty) { LussisEntities entity = new LussisEntities(); RequisitionDetail rrdd = entity.RequisitionDetails .Where(u => u.ReqNo == requisitionNo && u.ItemNo.Equals(itemNo)) .FirstOrDefault(); rrdd.Qty = qty; entity.SaveChanges(); }
public static void DeleteForDetail(int requisitionNo, string item) { LussisEntities entity = new LussisEntities(); RequisitionDetail rr = entity.RequisitionDetails .Where(u => u.ReqNo == requisitionNo && u.ItemNo.Equals(item)) .FirstOrDefault(); entity.RequisitionDetails.Remove(rr); entity.SaveChanges(); }
//Add data into database: requisition public static void RaisedRequisition(int issueBy, DateTime dateIssue, string status, List <RequisitionDetail> r) { using (LussisEntities entities = new LussisEntities()) { Requisition req = new Requisition { IssuedBy = issueBy, DateIssued = dateIssue, Status = status }; foreach (RequisitionDetail l in r) { RequisitionDetail rl = new RequisitionDetail(); rl.ReqNo = req.ReqNo; rl.ItemNo = l.ItemNo; rl.Qty = l.Qty; entities.RequisitionDetails.Add(l); } entities.Requisitions.Add(req); entities.SaveChanges(); LussisEntities entity = new LussisEntities(); Employee currEmployee = entity.Employees.Where(emp => emp.EmpNo == issueBy).First(); Department currDepartment = entity.Departments.Where(dep => dep.DeptCode.Equals(currEmployee.DeptCode)).First(); // Send Email to Head EmailBackend.sendEmailStep( currDepartment.EmployeeHead.Email, EmailTemplate.GeneratePendingRequisitionSubject(currEmployee.EmpName.ToString()), EmailTemplate.GeneratePendingRequisition(currDepartment.EmployeeHead.EmpName.ToString(), currEmployee.EmpName.ToString())); //Send email to Employee EmailBackend.sendEmailStep( currEmployee.Email, EmailTemplate.GenerateRaisedRequisitionSubject(), EmailTemplate.GenerateRaisedRequisition(currEmployee.EmpName.ToString(), req.ReqNo.ToString())); } }