public ActionResult Create([Bind(Include = "Id,Name,Cost")] Product product) { if (ModelState.IsValid) { db.Products.Add(product); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(product)); }
public IList <GridViewModel> GetTransactions(InputViewModel input) { TransactionLog transactionLog = new TransactionLog { FormName = "GetTransaction", JobStatus = "InProcess", RequestedBy = "User", StartTime = DateTime.UtcNow, CreatedBy = "User", UpdatedBy = "User", CreatedDatey = DateTime.UtcNow, UpdatedDate = DateTime.UtcNow, }; if (input.Environment == "Env-1") { context.TransactionLogs.Add(transactionLog); var saved = context.SaveChanges(); var query = context.Accounts.AsQueryable(); if (!string.IsNullOrEmpty(input.AccountNumber)) { query = query.Where(x => x.AccountId == input.AccountNumber); } if (!string.IsNullOrEmpty(input.ProductSelected)) { query = query.Where(x => x.ProdId == input.ProductSelected); } var result = query.Select(x => new GridViewModel { TransId = x.TransId, AccountNumber = x.AccountId, ProductNumber = x.ProdId, TransactionAmount = x.TransAmt, TransactionDescription = x.TransDesc, TransactionDate = x.TransDte ?? DateTime.UtcNow }).ToList(); var currentTransaction = context.TransactionLogs.FirstOrDefault(x => x.JobId == transactionLog.JobId); currentTransaction.EndTime = DateTime.UtcNow; currentTransaction.JobStatus = "Completed"; context.SaveChanges(); return(result); } if (input.Environment == "Env-2") { db2AppContext.TransactionLogs.Add(transactionLog); var saved = db2AppContext.SaveChanges(); var query = db2AppContext.Accounts.AsQueryable(); if (!string.IsNullOrEmpty(input.AccountNumber)) { query = query.Where(x => x.AccountId == input.AccountNumber); } if (!string.IsNullOrEmpty(input.ProductSelected)) { query = query.Where(x => x.ProdId == input.ProductSelected); } var result = query.Select(x => new GridViewModel { TransId = x.TransId, AccountNumber = x.AccountId, ProductNumber = x.ProdId, TransactionAmount = x.TransAmt, TransactionDescription = x.TransDesc, TransactionDate = x.TransDte ?? DateTime.UtcNow }).ToList(); var currentTransaction = db2AppContext.TransactionLogs.FirstOrDefault(x => x.JobId == transactionLog.JobId); currentTransaction.EndTime = DateTime.UtcNow; currentTransaction.JobStatus = "Completed"; context.SaveChanges(); return(result); } return(null); }