public costUpdationVM GetCostupdationbyCostUpID(int CostID) { costUpdationVM CostUp = new costUpdationVM(); if (CostID <= 0) { return(new costUpdationVM()); } var query = Context1.SP_GetCostUpdationByCostID(CostID); if (query != null) { var item = query.FirstOrDefault(); CostUp.AcJournalID = item.AcJournalID.Value; CostUp.InvoiceNo = item.InvoiceNo; CostUp.DocumentNo = item.DocumentNo; CostUp.SupplierID = item.SupplierID; CostUp.SelectedSupplierID = item.SupplierID; CostUp.InvoiceDate = item.InvoiceDate; CostUp.EmployeeID = item.EmployeeID; CostUp.JobID = item.JobID; CostUp.CostUpdationID = item.CostUpdationID; if (item.JobCode != null) { if (item.JobCode.StartsWith(",")) { CostUp.JobCode = item.JobCode.Substring(1); } else { CostUp.JobCode = item.JobCode; } } CostUp.SupplierName = item.SupplierName; CostUp.SupplierID = item.SupplierID; CostUp.TransactionDate = item.TransactionDate; CostUp.InvoiceAmount = item.InvoiceAmount; } else { return(new costUpdationVM()); } return(CostUp); }
public int SaveCostUpdation(costUpdationVM CU) { int costupdationId = 0; CostUpdation objcostUpdation = new CostUpdation(); //int i = Context1.SP_InsertCostUpdationAndDetails(CU.SupplierID, CU.JobID, CU.InvoiceNo, CU.InvoiceDate, CU.EmployeeID, // CU.DocumentNo, CU.SupplierPaymentStatus, CU.UserID, SupplierRef, Convert.ToDecimal(amountPaidTillDate)); //Edit Code if (CU.CostUpdationID > 0) { objcostUpdation = Context1.CostUpdations.Where(ite => ite.CostUpdationID == CU.CostUpdationID).FirstOrDefault(); if (objcostUpdation != null) { objcostUpdation.SupplierID = CU.SupplierID; objcostUpdation.JobID = CU.JobID; objcostUpdation.InvoiceNo = CU.InvoiceNo; objcostUpdation.InvoiceDate = CU.InvoiceDate; objcostUpdation.DocumentNo = CU.DocumentNo; objcostUpdation.SupplierPaymentStatus = CU.SupplierPaymentStatus; objcostUpdation.UserID = CU.UserID; objcostUpdation.EmployeeID = CU.EmployeeID; objcostUpdation.CostUpdationID = CU.CostUpdationID; objcostUpdation.AcJournalID = CU.AcJournalID; objcostUpdation.TransactionDate = CU.TransactionDate; objcostUpdation.InvoiceAmount = CU.InvoiceAmount; Context1.Entry(objcostUpdation).State = EntityState.Modified; Context1.SaveChanges(); costupdationId = objcostUpdation.CostUpdationID; } } else { // foreach (var item in CU.MultiJobID) // { // CU.InvoiceNo = GetInvoiceNoByJobID(0); objcostUpdation = new CostUpdation(); var costupdations = Context1.CostUpdations; var maxValue = 0; int MaxcostupdationID = 0; if (costupdations.Count() > 0) { maxValue = Context1.CostUpdations.Max(x => x.CostUpdationID); MaxcostupdationID = Context1.CostUpdations.First(x => x.CostUpdationID == maxValue).CostUpdationID; } if (Convert.ToInt32(MaxcostupdationID) <= 0) { MaxcostupdationID = 1; } else { MaxcostupdationID = (MaxcostupdationID) + 1; } // int MaxcostupdationID = 33831; objcostUpdation.CostUpdationID = MaxcostupdationID; objcostUpdation.SupplierID = CU.SupplierID; objcostUpdation.JobID = 0; objcostUpdation.InvoiceNo = CU.InvoiceNo; objcostUpdation.InvoiceDate = CU.InvoiceDate; objcostUpdation.DocumentNo = CU.DocumentNo; objcostUpdation.SupplierPaymentStatus = CU.SupplierPaymentStatus; objcostUpdation.UserID = CU.UserID; objcostUpdation.EmployeeID = CU.EmployeeID; // objcostUpdation.AcJournalID = CU.AcJournalID; objcostUpdation.PrevCostupID = CU.PrevCostupID; objcostUpdation.TransactionDate = CU.TransactionDate; objcostUpdation.InvoiceAmount = CU.InvoiceAmount; //Updation Jinvoice Entry //todo: sethu. move this to cost detail insert /* var joinvoice = Context1.JInvoices.Where(ite => ite.JobID == item && ite.SupplierID == CU.SupplierID).ToList(); * foreach (var objjoince in joinvoice) * { * objjoince.CostUpdationStatus = "2"; * }*/ // 5000,1,1,'','2016-1-1',1,1,'','',1,0 Context1.SP_InsertCostUpdation(objcostUpdation.CostUpdationID, objcostUpdation.SupplierID.Value, objcostUpdation.JobID.Value, objcostUpdation.InvoiceNo, objcostUpdation.InvoiceDate, 0, objcostUpdation.EmployeeID.Value, objcostUpdation.DocumentNo, objcostUpdation.PrevCostupID, objcostUpdation.SupplierPaymentStatus, objcostUpdation.UserID.Value, false, objcostUpdation.TransactionDate, objcostUpdation.InvoiceAmount); // Context1.CostUpdations.Add(objcostUpdation); Context1.SaveChanges(); costupdationId = objcostUpdation.CostUpdationID; // } } return(costupdationId); }