public async Task <Supplier> AddSupplier(string name, string supplierCode) { _logger.LogInformation(Resources.CreatingSupplierLogMessage, supplierCode); try { var res = await _dal.CreateSupplier(name, supplierCode); var dSupplier = await _dal.GetSupplierByID(res); return(dSupplier); } catch (Exception ex) { _logger.LogError("Error occurred adding a supplier {0}\t{1}", supplierCode, ex.Message); throw new HttpRequestException("Failed to add the supplier: " + ex.Message); } }
public ActionResult Create([Bind(Include = "supplierId,supplierName,contactName,phone,fax,address,email,gstNo")] Supplier supplier) { try { if (ModelState.IsValid) { SupplierDAO.CreateSupplier(supplier); return(RedirectToAction("Index")); } return(View(supplier)); } catch (Exception e) { return(View("~/Views/Shared/Error.cshtml")); } }
public ActionResult CreateSupplier(SupplierPO form) { ActionResult response; //Check if valid info was given, Back to create supplier view page if not. if (ModelState.IsValid) { try { //Map given info to DO. SupplierDO newSupplier = SupplierMapper.PoToDo(form); //Create supplier in SQL, giving DO info. _SupplierDAO.CreateSupplier(newSupplier); //Return to view all supplier page. response = RedirectToAction("Index", "Supplier"); } catch (SqlException sqlex) { response = RedirectToAction("Error", "Shared"); } catch (Exception ex) { response = RedirectToAction("Error", "Shared"); Logger.ErrorLogPath = _LogPath; Logger.ExceptionLog(ex); } } else { response = View(); } return(response); }
public void CreateSupplier(Supplier supplier) { sDAO.makeConnection(); sDAO.CreateSupplier(supplier); sDAO.closeConnection(); }
static void Main(string[] args) { bool continueProgram = true; while (continueProgram) { Console.Clear(); Console.ResetColor(); Console.WriteLine("What would you like to do?\n"); Console.WriteLine("\t" + "1) View all Suppliers"); Console.WriteLine("\t" + "2) Add a new Supplier"); Console.WriteLine("\t" + "3) Update Supplier Information"); Console.WriteLine("\t" + "4) Delete a Supplier"); Console.WriteLine("\t" + "5) Exit Application"); switch (Console.ReadKey(true).Key) { case ConsoleKey.NumPad1: case ConsoleKey.D1: List <SupplierDO> allSuppliers = dao.ObtainAllSuppliers(); List <SupplierPO> supplierInfo = Mapper.FromDoToPo(allSuppliers); for (int i = 0; i < supplierInfo.Count; i++) { ViewAllSuppliers(supplierInfo[i]); } Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Press any key to continue"); Console.ReadKey(); break; case ConsoleKey.NumPad2: case ConsoleKey.D2: Console.Clear(); SupplierPO supplier = new SupplierPO(); UserInput(supplier); SupplierDO newSupp = Mapper.PoToDo(supplier); dao.CreateSupplier(newSupp); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("Data Stored"); Thread.Sleep(1800); break; case ConsoleKey.NumPad3: case ConsoleKey.D3: Console.Clear(); SupplierPO udatedSupplier = new SupplierPO(); UpdateInformation(udatedSupplier); break; case ConsoleKey.NumPad4: case ConsoleKey.D4: Console.Clear(); int suppId = GetId(); dao.DeleteSupplier(suppId); Console.Clear(); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Entry Successfully deleted"); Thread.Sleep(1800); break; case ConsoleKey.NumPad5: case ConsoleKey.D5: continueProgram = false; Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Shutting down program"); Thread.Sleep(1800); break; } } }