public ActionResult Edit(Employee employee, HttpPostedFileBase file) { AssetLogic al = new AssetLogic(); if (ModelState.IsValid) { var _employee = _context.Employees.Find(employee.employeeNumber); if (file != null && file.ContentLength > 0) { employee.fileName = System.IO.Path.GetFileName(file.FileName); employee.fileType = file.ContentType; employee.fileBytes = al.ConvertToBytes(file); } else { employee.fileName = _employee.fileName; employee.fileType = _employee.fileType; employee.fileBytes = _employee.fileBytes; } employee.fullname = employee.firstName + " " + employee.lastName; _context.Entry(_employee).State = EntityState.Detached; _context.Entry(employee).State = EntityState.Modified; _context.SaveChanges(); return(RedirectToAction("UserProfile")); } ViewBag.RoleID = new SelectList(_context.Roles, "RoleID", "RoleName", employee.RoleID); ViewBag.departmentID = new SelectList(_context.Departments, "departmentID", "departmentName", employee.departmentID); return(View(employee)); }
/// <summary> /// Exports the specified instance properties to the provided stream. /// </summary> /// <param name="qif">The <seealso cref="T:QifDom"/> to export.</param> /// <param name="stream">Stream.</param> /// <param name="encoding">Encoding.</param> /// <remarks>This will overwrite an existing file.</remarks> public static void ExportStream(QifDom qif, Stream stream, Encoding encoding = null) { encoding = encoding ?? Encoding.UTF8; using (StreamWriter writer = new StreamWriter(stream, encoding, 512, true)) { writer.AutoFlush = true; AccountListLogic.Export(writer, qif.AccountListTransactions); AssetLogic.Export(writer, qif.AssetTransactions); BankLogic.Export(writer, qif.BankTransactions); CashLogic.Export(writer, qif.CashTransactions); CategoryListLogic.Export(writer, qif.CategoryListTransactions); ClassListLogic.Export(writer, qif.ClassListTransactions); CreditCardLogic.Export(writer, qif.CreditCardTransactions); InvestmentLogic.Export(writer, qif.InvestmentTransactions); LiabilityLogic.Export(writer, qif.LiabilityTransactions); MemorizedTransactionListLogic.Export(writer, qif.MemorizedTransactionListTransactions); } }
/// <summary> /// Exports the specified instance properties to the specified file. /// </summary> /// <param name="qif">The <seealso cref="T:QifDom"/> to export.</param> /// <param name="fileName">Name of the file.</param> /// <param name="encoding"> /// The encoding to use when exporting the QIF file. This defaults to UTF8 /// when not specified. /// </param> /// <remarks>This will overwrite an existing file.</remarks> public static void ExportFile(QifDom qif, string fileName, Encoding encoding = null) { if (File.Exists(fileName)) { File.SetAttributes(fileName, FileAttributes.Normal); } using (StreamWriter writer = new StreamWriter(fileName, false, encoding ?? Encoding.UTF8)) { writer.AutoFlush = true; AccountListLogic.Export(writer, qif.AccountListTransactions, qif.Configuration); AssetLogic.Export(writer, qif.AssetTransactions, qif.Configuration); BankLogic.Export(writer, qif.BankTransactions, qif.Configuration); CashLogic.Export(writer, qif.CashTransactions, qif.Configuration); CategoryListLogic.Export(writer, qif.CategoryListTransactions, qif.Configuration); ClassListLogic.Export(writer, qif.ClassListTransactions, qif.Configuration); CreditCardLogic.Export(writer, qif.CreditCardTransactions, qif.Configuration); InvestmentLogic.Export(writer, qif.InvestmentTransactions, qif.Configuration); LiabilityLogic.Export(writer, qif.LiabilityTransactions, qif.Configuration); MemorizedTransactionListLogic.Export(writer, qif.MemorizedTransactionListTransactions, qif.Configuration); } }
public ActionResult Add(LaptopViewModel viewmodel, string modelName) { ViewBag.LM = context.Stocks.ToList().Where(x => x.category == "Laptop"); List <Stock> slist = new List <Stock>(context.Stocks.ToList().Where(x => x.category == "Laptop")); List <SelectListItem> li = new List <SelectListItem>(); foreach (var item in slist) { var man = li.Find(x => x.Value == item.manufacturer); if (man == null) { li.Add(new SelectListItem { Text = item.manufacturer, Value = item.manufacturer }); } } viewmodel.modelName = modelName; ViewBag.LL = li; ViewBag.LM = context.Stocks.ToList().Where(x => x.category == "Laptop"); if (ModelState.IsValid) { AssetLogic al = new AssetLogic(); try { Stock stock = context.Stocks.FirstOrDefault(m => m.model.Equals(viewmodel.modelName) && m.manufacturer.Equals(viewmodel.manufacturer) && m.category.Equals("Laptop")); if (stock != null && stock.quantity != 0) { var asset = new Asset { manufacturer = viewmodel.manufacturer, serialNumber = viewmodel.serialNumber, dateadded = viewmodel.dateAdded, warranty = viewmodel.warranty + " Months", costprice = viewmodel.costprice, InvoiceNumber = viewmodel.InvoiceNumber, depreciationcost = al.depreciationCost(viewmodel.dateAdded, viewmodel.costprice) }; var laptop = new Laptop { serialNumber = viewmodel.serialNumber, manufacturer = viewmodel.manufacturer, modelName = viewmodel.modelName, warranty = viewmodel.warranty + " Months", dateAdded = viewmodel.dateAdded, HDD = viewmodel.HDD, OS = viewmodel.OS, RAM = viewmodel.RAM, screenSize = viewmodel.screenSize, InvoiceNumber = viewmodel.InvoiceNumber, processor = viewmodel.processor }; stock.quantity = stock.quantity - 1; repository.Insert(asset, laptop); repository.Save(); context.SaveChanges(); TempData["Success"] = "Asset has been added!"; } else { ViewBag.Message = "Asset model not available in stock. Update your stock."; } } catch (Exception e) { ViewBag.Message = "Asset not added. Error: " + e.Message; } } ModelState.Clear(); return(View(viewmodel)); }
/// <summary> /// Imports a QIF file stream reader and returns a QifDom object. /// </summary> /// <param name="reader">The stream reader pointing to an underlying QIF file to import.</param> /// <param name="config">The configuration to use while importing raw data</param> /// <returns>A QifDom object of transactions imported.</returns> public static QifDom ImportFile(StreamReader reader, Configuration config = null) { QifDom result = new QifDom(config); // Read the entire file string input = reader.ReadToEnd(); // Split the file by header types string[] transactionTypes = Regex.Split(input, @"^(!.*)$", RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace); // Loop through the transaction types for (int i = 0; i < transactionTypes.Length; i++) { // Get the exact transaction type string transactionType = transactionTypes[i].Replace("\r", "").Replace("\n", "").Trim(); // If the string has a value if (transactionType.Length > 0) { // Check the transaction type switch (transactionType) { case Headers.Bank: // Increment the array counter i++; // Extract the transaction items string bankItems = transactionTypes[i]; // Import all transaction types result.BankTransactions.AddRange(BankLogic.Import(bankItems, result.Configuration)); // All done break; case Headers.AccountList: // Increment the array counter i++; // Extract the transaction items string accountListItems = transactionTypes[i]; // Import all transaction types result.AccountListTransactions.AddRange(AccountListLogic.Import(accountListItems, result.Configuration)); // All done break; case Headers.Asset: // Increment the array counter i++; // Extract the transaction items string assetItems = transactionTypes[i]; // Import all transaction types result.AssetTransactions.AddRange(AssetLogic.Import(assetItems, result.Configuration)); // All done break; case Headers.Cash: // Increment the array counter i++; // Extract the transaction items string cashItems = transactionTypes[i]; // Import all transaction types result.CashTransactions.AddRange(CashLogic.Import(cashItems, result.Configuration)); // All done break; case Headers.CategoryList: // Increment the array counter i++; // Extract the transaction items string catItems = transactionTypes[i]; // Import all transaction types result.CategoryListTransactions.AddRange(CategoryListLogic.Import(catItems, result.Configuration)); // All done break; case Headers.ClassList: // Increment the array counter i++; // Extract the transaction items string classItems = transactionTypes[i]; // Import all transaction types result.ClassListTransactions.AddRange(ClassListLogic.Import(classItems, result.Configuration)); // All done break; case Headers.CreditCard: // Increment the array counter i++; // Extract the transaction items string ccItems = transactionTypes[i]; // Import all transaction types result.CreditCardTransactions.AddRange(CreditCardLogic.Import(ccItems, result.Configuration)); // All done break; case Headers.Investment: // Increment the array counter i++; // Extract the transaction items string investItems = transactionTypes[i]; // Import all transaction types result.InvestmentTransactions.AddRange(InvestmentLogic.Import(investItems, result.Configuration)); // All done break; case Headers.Liability: // Increment the array counter i++; // Extract the transaction items string liabilityItems = transactionTypes[i]; // Import all transaction types result.LiabilityTransactions.AddRange(LiabilityLogic.Import(liabilityItems, result.Configuration)); // All done break; case Headers.MemorizedTransactionList: // Increment the array counter i++; // Extract the transaction items string memItems = transactionTypes[i]; // Import all transaction types result.MemorizedTransactionListTransactions.AddRange(MemorizedTransactionListLogic.Import(memItems, result.Configuration)); // All done break; default: // Don't do any processing break; } } } return(result); }
/// <summary> /// Imports a QIF file stream reader and returns a QifDom object. /// </summary> /// <param name="reader">The stream reader pointing to an underlying QIF file to import.</param> /// <param name="config">The configuration to use while importing raw data</param> /// <returns>A QifDom object of transactions imported.</returns> public static QifDom ImportFile(TextReader reader, Configuration config = null) { QifDom result = new QifDom(config); // Read the entire file string input = reader.ReadToEnd(); // Split the file by header types string[] transactionTypes = Regex.Split(input, @"^(!.*)$", RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace); // Remember the last account name we saw so we can link its transactions to it. string currentAccountName = string.Empty; // Loop through the transaction types for (int i = 0; i < transactionTypes.Length; i++) { // Get the exact transaction type string transactionType = transactionTypes[i].Replace("\r", "").Replace("\n", "").Trim(); // If the string has a value if (transactionType.Length > 0) { // Check the transaction type switch (transactionType) { case Headers.Bank: // Increment the array counter i++; // Extract the transaction items string bankItems = transactionTypes[i]; // Import all transaction types var transactions = BankLogic.Import(bankItems, result.Configuration); // Associate the transactions with last account we saw. foreach (var transaction in transactions) { transaction.AccountName = currentAccountName; } result.BankTransactions.AddRange(transactions); // All done break; case Headers.AccountList: // Increment the array counter i++; // Extract the transaction items string accountListItems = transactionTypes[i]; // Import all transaction types var accounts = AccountListLogic.Import(accountListItems, result.Configuration); // Remember account so transaction following can be linked to it. currentAccountName = accounts.Last().Name; result.AccountListTransactions.AddRange(accounts); // All done break; case Headers.Asset: // Increment the array counter i++; // Extract the transaction items string assetItems = transactionTypes[i]; // Import all transaction types result.AssetTransactions.AddRange(AssetLogic.Import(assetItems, result.Configuration)); // All done break; case Headers.Cash: // Increment the array counter i++; // Extract the transaction items string cashItems = transactionTypes[i]; // Import all transaction types result.CashTransactions.AddRange(CashLogic.Import(cashItems, result.Configuration)); // All done break; case Headers.CategoryList: // Increment the array counter i++; // Extract the transaction items string catItems = transactionTypes[i]; // Import all transaction types result.CategoryListTransactions.AddRange(CategoryListLogic.Import(catItems, result.Configuration)); // All done break; case Headers.ClassList: // Increment the array counter i++; // Extract the transaction items string classItems = transactionTypes[i]; // Import all transaction types result.ClassListTransactions.AddRange(ClassListLogic.Import(classItems, result.Configuration)); // All done break; case Headers.TagList: // Increment the array counter i++; // Extract the transaction items string tagListItems = transactionTypes[i]; // Import all transaction types result.TagListTransactions.AddRange(TagListLogic.Import(tagListItems, result.Configuration)); // All done break; case Headers.CreditCard: // Increment the array counter i++; // Extract the transaction items string ccItems = transactionTypes[i]; // Import all transaction types result.CreditCardTransactions.AddRange(CreditCardLogic.Import(ccItems, result.Configuration)); // All done break; case Headers.Investment: // Increment the array counter i++; // Extract the transaction items string investItems = transactionTypes[i]; // Import all transaction types result.InvestmentTransactions.AddRange(InvestmentLogic.Import(investItems, result.Configuration)); // All done break; case Headers.Liability: // Increment the array counter i++; // Extract the transaction items string liabilityItems = transactionTypes[i]; // Import all transaction types result.LiabilityTransactions.AddRange(LiabilityLogic.Import(liabilityItems, result.Configuration)); // All done break; case Headers.MemorizedTransactionList: // Increment the array counter i++; // Extract the transaction items string memItems = transactionTypes[i]; // Import all transaction types result.MemorizedTransactionListTransactions.AddRange(MemorizedTransactionListLogic.Import(memItems, result.Configuration)); // All done break; default: // Don't do any processing break; } } } return(result); }
public IndexModel() { assetLogic = new AssetLogic(); }
public ActionResult Add(MouseViewModel viewmodel) { ViewBag.LM = db.Stocks.ToList().Where(x => x.category == "Mouse"); List <Stock> slist = new List <Stock>(db.Stocks.ToList().Where(x => x.category == "Mouse")); List <SelectListItem> li = new List <SelectListItem>(); foreach (var item in slist) { var man = li.Find(x => x.Value == item.manufacturer); if (man == null) { li.Add(new SelectListItem { Text = item.manufacturer, Value = item.manufacturer }); } } ViewBag.MouseM = li; if (ModelState.IsValid) { try { var stock = db.Stocks.FirstOrDefault(m => m.model.Equals(viewmodel.modelName) && m.manufacturer.Equals(viewmodel.manufacturer) && m.category.Equals("Mouse")); if (stock != null && stock.quantity != 0) { AssetLogic al = new AssetLogic(); var asset = new Asset { manufacturer = viewmodel.manufacturer, serialNumber = viewmodel.serialNumber, dateadded = viewmodel.dateAdded, warranty = viewmodel.warranty + " Months", costprice = viewmodel.costprice, InvoiceNumber = viewmodel.InvoiceNumber, depreciationcost = al.depreciationCost(viewmodel.dateAdded, viewmodel.costprice) }; var mouse = new Mouse { serialNumber = viewmodel.serialNumber, manufacturer = viewmodel.manufacturer, modelName = viewmodel.modelName, warranty = viewmodel.warranty + " Months", dateAdded = viewmodel.dateAdded, InvoiceNumber = viewmodel.InvoiceNumber }; stock.quantity = stock.quantity - 1; _repository.Insert(asset, mouse); _repository.Save(); db.SaveChanges(); TempData["Success"] = "Asset has been added!"; ModelState.Clear(); } else { ViewBag.Message = "Asset model not available in stock. Update your stock."; } } catch (Exception e) { ViewBag.Message = "Asset not added. Error: " + e.Message; } } return(View(viewmodel)); }
public CrudTest() { _assetLogic = new AssetLogic(); }
public EditModel() { assetLogic = new AssetLogic(); }
public CreateModel() { assetLogic = new AssetLogic(); }