public Requisition GetAll() { Requisition req = context.Requisitions.FirstOrDefault(); return(req); }
public void Save(Requisition req) { bool reqExists = context.Requisitions.Any(p => p.No == req.No); req.No = GenerateReqNo(req.Date); int id; if (!reqExists) { context.Requisitions.Add(req); context.SaveChanges(); id = req.Id; foreach (RequisitionItem reqItem in req.RequisitionItems) { reqItem.RequisitionId = id; if (reqItem.Quantity != 0) { reqItem.TransactionLogId = InsertLogs(reqItem.ItemId, reqItem.Quantity, req.Date); InsertStockCard(id, reqItem.ItemId, reqItem.GetItemUnitCost, reqItem.Quantity, reqItem.TransactionLogId); } } } else { Requisition dbEntry = context.Requisitions.FirstOrDefault(p => p.No == req.No); if (dbEntry != null) { dbEntry.JobOrderDate = req.Date; dbEntry.JobOrderNo = req.JobOrderNo; dbEntry.UnitPlateNo = req.UnitPlateNo; dbEntry.JobOrderDate = req.JobOrderDate; dbEntry.OdometerReading = req.OdometerReading; dbEntry.DriverName = req.DriverName; dbEntry.ReportedBy = req.ReportedBy; dbEntry.CheckedBy = req.CheckedBy; dbEntry.ApprovedBy = req.ApprovedBy; dbEntry.CompanyId = req.CompanyId; } context.SaveChanges(); id = dbEntry.Id; //Delete previous items foreach (RequisitionItem reqItem in dbEntry.RequisitionItems.ToList()) { //Delete previous logs TransactionLogRepository transLogRepo = new TransactionLogRepository(); transLogRepo.Remove(reqItem.TransactionLogId.Value); reqItemRepo.Remove(reqItem.Id); } foreach (RequisitionItem reqItem in req.RequisitionItems) { reqItem.RequisitionId = id; if (reqItem.Quantity != 0) { reqItem.TransactionLogId = InsertLogs(reqItem.ItemId, reqItem.Quantity, req.Date); } context.RequisitionItems.Add(reqItem); } } int vehicleId = vehicleRepo.GetIdByPlateNo(req.UnitPlateNo); int?translogId = req.RequisitionItems.Last().TransactionLogId; SaveVehicle(vehicleId, translogId); context.SaveChanges(); }
public Requisition GetByNo(string reqNo) { Requisition req = context.Requisitions.FirstOrDefault(p => p.No == reqNo); return(req); }