public ActionResult UpdateEmployee(Employee criteria) { if (criteria.Name == "") { return(RedirectToAction("Edit")); } if (criteria.Dept == "") { return(RedirectToAction("Edit")); } try { using (var dbContext = new CompanyDbEntities()) { Employee employee = dbContext.Employees.Where(obj => obj.Id == criteria.Id).FirstOrDefault(); employee.Name = criteria.Name; employee.Dept = criteria.Dept; dbContext.Entry(employee).State = EntityState.Modified; dbContext.SaveChanges(); } } catch { } return(RedirectToAction("Index")); }
public ActionResult InsertEmployee(Employee employee) { if (employee.Name == "") { return(RedirectToAction("NewEmployee")); } if (employee.Dept == "") { return(RedirectToAction("NewEmployee")); } try { using (var dbContext = new CompanyDbEntities()) { int maximumId = 0; maximumId = dbContext.Employees.Max(obj => obj.Id); employee.Id = maximumId + 1; employee.CreatedDateTime = DateTime.Now; employee.IsDeleted = false; dbContext.Employees.Add(employee); dbContext.SaveChanges(); } } catch { } return(RedirectToAction("Index")); }
public IList <Employee> GenerateRandomEmployees(int count, CompanyDbEntities db) { this.alreadyGeneratedCount = 0; this.generateCount = count; this.db = db; this.generateCount = count; this.generatedEmployees = new List <Employee>(count); this.managers = new List <Employee>(); for (int i = 0; i < this.generateCount; i++) { var newEmployee = new Employee() { FirstName = this.GetString(5, 20, DataType.LowerLetters), LastName = this.GetString(5, 20, DataType.LowerLetters), DepartmentID = GetAssignedDepartmentId(), Employee1 = GetAssignedManager(), YearlySalary = this.GetSalary(), }; if (newEmployee.Employee1 == null) { this.managers.Add(newEmployee); } this.generatedEmployees.Add(newEmployee); this.alreadyGeneratedCount++; } return(this.generatedEmployees); }
public ActionResult Edit(int Id) { Employee employee; using (var dbContext = new CompanyDbEntities()) { employee = dbContext.Employees.Where(obj => obj.Id == Id).FirstOrDefault(); } return(View(employee)); }
public ActionResult Index() { List <Employee> employees = new List <Employee>(); using (var dbContext = new CompanyDbEntities()) { employees = dbContext.Employees.Where(obj => obj.IsDeleted == false).ToList(); ViewBag.Message = "OK"; } return(View(employees)); }
public ActionResult DeleteEmployee(int Id) { try { using (var dbContext = new CompanyDbEntities()) { Employee employee = dbContext.Employees.Where(obj => obj.Id == Id).FirstOrDefault(); dbContext.Employees.Remove(employee); dbContext.SaveChanges(); } } catch { } return(RedirectToAction("Index")); }
public static void Main() { var depCount = 100; var projectCount = 1000; var reportCount = 250000; var empCount = 5000; var db = new CompanyDbEntities(); db.Configuration.AutoDetectChangesEnabled = false; var depGenerator = new RandomDepartmentGenerator(); var departments = depGenerator.GenerateDepartments(depCount); db.Departments.AddRange(departments); db.SaveChanges(); var projGenerator = new RandomProjectGenerator(); var projects = projGenerator.GenerateRandomProjects(projectCount); var employeeGeneratr = new RandomEmployeeGenerator(); var employees = employeeGeneratr.GenerateRandomEmployees(empCount, db); var reportGenerator = new RandomReportGenerator(); var reports = reportGenerator.GenerateReports(reportCount, employees); var emplProjGenerator = new RandomEmployeeProjectsGenerator(); var emplProjects = emplProjGenerator.Generate(projectCount, employees, projects); db.Reports.AddRange(reports); db.EmployeesProjects.AddRange(emplProjects); try { db.SaveChanges(); } catch (Exception ex) { System.Console.WriteLine(ex.Message); } db.Configuration.AutoDetectChangesEnabled = true; }
static void Main(string[] args) { bool flag = true; var dbContext = new CompanyDbEntities(); while (flag) { Console.WriteLine("1. Add Plant Details"); Console.WriteLine("2. Show Plnts"); Console.WriteLine("3. Add Toy Details"); Console.WriteLine("4. Show Toys"); Console.WriteLine("5. Add Customer Details"); Console.WriteLine("6. Show Customer \n 7. Add Shipping Address \n 8. Create Wallet"); Console.WriteLine("9. Place an Order"); Console.WriteLine("10. List of Order"); Console.WriteLine("11. Exit"); Console.WriteLine("Enter your Choice: "); int choice = Convert.ToInt32(Console.ReadLine()); switch (choice) { case 1: AddPlant(); break; case 2: PlantList(); break; case 3: AddToy(); break; case 4: ToyList(); break; case 5: AddCustomer(); break; case 6: CustomerList(); break; case 7: Console.WriteLine("Enter Your Customer Id: "); CustomerList(); int custId = Convert.ToInt32(Console.ReadLine()); AddShippingAddress(custId); break; case 8: Console.WriteLine("Enter Your Customer Id: "); CustomerList(); int custId2 = Convert.ToInt32(Console.ReadLine()); CreateWallet(custId2); break; case 9: PlaceOrder(); break; case 10: Console.WriteLine("Enter Your Customer Id: "); CustomerList(); int custId1 = Convert.ToInt32(Console.ReadLine()); OrderList(custId1); break; case 11: flag = false; break; default: break; } } void AddToy() { using (dbContext) { var toy = new Toy(); Console.WriteLine("Enter Toy Name: "); toy.ToyName = Console.ReadLine(); var check = dbContext.Toys.SingleOrDefault(t => t.ToyName == toy.ToyName); if (check == null) { try { dbContext.Toys.Add(toy); dbContext.SaveChanges(); Console.WriteLine("Toy added to the list"); } catch (Exception e) { Console.WriteLine(e); } } else { Console.WriteLine("Toy is already in the list"); } } } void AddCustomer() { using (dbContext) { var customer = new Customer(); Console.WriteLine("Enter Customer Name: "); customer.Name = Console.ReadLine(); Console.WriteLine("Enter Customer Address: "); customer.Address = Console.ReadLine(); Console.WriteLine("Enter Customer Contact Number: "); customer.ContactNo = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Enter Customer Gender: "); customer.Gender = Console.ReadLine(); var check = dbContext.Customers.SingleOrDefault(t => t.Name == customer.Name); if (check == null) { try { dbContext.Customers.Add(customer); dbContext.SaveChanges(); Console.WriteLine("Customer added to the list"); } catch (Exception e) { Console.WriteLine(e); } } else { Console.WriteLine("Customer is already in the list"); } } } void AddPlant() { using (dbContext) { var plant = new Plant(); Console.WriteLine("Enter Plant Name: "); plant.PlantName = Console.ReadLine(); var check = dbContext.Plants.SingleOrDefault(t => t.PlantName == plant.PlantName); if (check == null) { try { dbContext.Plants.Add(plant); dbContext.SaveChanges(); Console.WriteLine("Plant added to the list"); } catch (Exception e) { Console.WriteLine(e); } } else { Console.WriteLine("Plant is already in the list"); } } } void AddShippingAddress(int custId) { var db = new CompanyDbEntities(); var addList = db.ShippingAddresses; var check1 = db.ShippingAddresses.Where(t => t.CustomerId == custId); if (check1 != null) { try { foreach (var t in addList) { Console.WriteLine("\tCustomer Id: " + t.CustomerId + "\tAddress : " + t.Address + "\tCity : " + t.City + "\tState: " + t.State); } } catch (Exception e) { Console.WriteLine(e); } } var check = db.ShippingAddresses.Find(custId); if (check != null) { using (dbContext) { var shippingAddress = new ShippingAddress(); shippingAddress.CustomerId = custId; Console.WriteLine("Enter Address : "); shippingAddress.Address = Console.ReadLine(); Console.WriteLine("Enter City: "); shippingAddress.City = Console.ReadLine(); Console.WriteLine("Enter State: "); shippingAddress.State = Console.ReadLine(); db.ShippingAddresses.Add(shippingAddress); db.SaveChanges(); Console.WriteLine("Address is added !!"); } } } void CreateWallet(int custId) { using (dbContext) { var wallet = new Wallet(); Console.WriteLine("Enter Balance : "); wallet.Balance = Convert.ToInt32(Console.ReadLine()); wallet.CustomerId = custId; var check = dbContext.Wallets.SingleOrDefault(t => t.CustomerId == wallet.CustomerId); if (check == null) { try { dbContext.Wallets.Add(wallet); dbContext.SaveChanges(); Console.WriteLine("Wallet is created !!!"); } catch (Exception e) { Console.WriteLine(e); } } else { Console.WriteLine("Wallet is already in the list"); var w = dbContext.Wallets; try { foreach (var t in w) { Console.WriteLine("\tCustomer Id: " + t.CustomerId + "\tBalance: " + t.Balance); } } catch (Exception e) { Console.WriteLine(e); } } } } void PlaceOrder() { using (var dbContext1 = new CompanyDbEntities()) { var order = new Order(); Console.WriteLine("Select Your Id: "); CustomerList(); order.CustomerId = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Select Toy Id for Order : "); ToyList(); order.ToyId = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Enter Quantity : "); order.ToyQuantity = Convert.ToInt32(Console.ReadLine()); int pAmount, orderId; using (var db = new CompanyDbEntities()) { var productAmount = db.spProductAmount(order.ToyId, order.ToyQuantity).FirstOrDefault().ToString(); pAmount = Convert.ToInt32(productAmount); Console.WriteLine("Product Amount : " + productAmount); } order.TotalAmount = pAmount; var check = dbContext1.Orders.SingleOrDefault(t => t.OrderId == order.OrderId); if (check == null) { try { dbContext1.Orders.Add(order); dbContext1.SaveChanges(); Console.WriteLine("\t Order is Placed ! \n Select Shipping address from below :--"); int shipId = ShippingAddressList(); SqlConnection connection = new SqlConnection("data source=DESKTOP-S5TQEIB\\SQLEXPRESS;initial catalog=CompanyDb;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"); SqlCommand execStoreProc = new SqlCommand(); execStoreProc.CommandType = System.Data.CommandType.StoredProcedure; execStoreProc.CommandText = "spOrderToy"; execStoreProc.Connection = connection; execStoreProc.Parameters.Add("@OrderId", order.OrderId); execStoreProc.Parameters.Add("@ShippingId", shipId); using (connection) { connection.Open(); SqlDataReader reader; using (reader = execStoreProc.ExecuteReader()) { while (reader.Read()) { // var amount = reader.GetValue(0); Console.WriteLine("------------Proceed to Pay-----------"); Console.WriteLine("\tTotal Amount to pay: " + Convert.ToInt32(reader["TotalCartAmount"])); int amount = Convert.ToInt32(reader["TotalCartAmount"]); int cartId = Convert.ToInt32(reader["CartId"]); Console.WriteLine("Select Your Customer Id: "); CustomerList(); int custId = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Your Customer Id :" + custId); WalletList(custId); //wallet based on custId ProceedToPay(custId, cartId, amount); } } } //int cartTotalAmount; //using (var db = new CompanyDbEntities()) //{ // var cartAmount = db.spOrderToy(order.OrderId, shipId).FirstOrDefault().ToString(); // Console.WriteLine("--------" + cartAmount); // for(var i=0; i<cartAmount.Length; i++) // { // Console.WriteLine("1 " + cartAmount[i]); // } // pAmount = Convert.ToInt32(cartAmount.Equals("TotalCartAmount")); // orderId = Convert.ToInt32(cartAmount.Equals("OrderId")); // Console.WriteLine("\tTotal Cart Amount : " + cartAmount + "\tOrder Id: " + orderId); // //var payment = new Payment(); //payment.CartId = cart.CartId; // } } catch (Exception e) { Console.WriteLine(e); } } else { Console.WriteLine("Order is already placed"); } } } void ProceedToPay(int custId, int cartId, int amount) { SqlConnection connection1 = new SqlConnection("data source=DESKTOP-S5TQEIB\\SQLEXPRESS;initial catalog=CompanyDb;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"); SqlCommand execStoreProc = new SqlCommand(); execStoreProc.CommandType = System.Data.CommandType.StoredProcedure; execStoreProc.CommandText = "spPayment"; execStoreProc.Connection = connection1; execStoreProc.Parameters.Add("@CustomerId", custId); execStoreProc.Parameters.Add("@CartId", cartId); execStoreProc.Parameters.Add("@Amount", amount); using (connection1) { connection1.Open(); SqlDataReader reader; using (reader = execStoreProc.ExecuteReader()) { while (reader.Read()) { int balance = Convert.ToInt32(reader["Balance"]); Console.WriteLine("------------Updated Balance :-----------"); Console.WriteLine(balance); } } } } void WalletList(int custId) { var db = new CompanyDbEntities(); var w = db.Wallets; var check = db.Wallets.Where(t => t.CustomerId == custId); if (check == null) { Console.WriteLine("You have not created a wallet yet !!\nCreate a wallet first"); } else { try { foreach (var t in w) { Console.WriteLine("\tCustomer Id: " + t.CustomerId + "\tWallet ID : " + t.WalletId + "\tBalance : " + t.Balance); } } catch (Exception e) { Console.WriteLine(e); } } } int ShippingAddressList() { var db = new CompanyDbEntities(); var addList = db.ShippingAddresses; try { foreach (var t in addList) { Console.WriteLine("\tCustomer Id: " + t.CustomerId + "\tAddress: " + t.Address + "\tCity : " + t.City + "\tState : " + t.State); } } catch (Exception e) { Console.WriteLine(e); } Console.WriteLine("Select an Address for shipping: "); return(Convert.ToInt32(Console.ReadLine())); } void OrderList(int custId) { var db = new CompanyDbEntities(); var orderList = db.Orders; var check = db.Orders.Where(t => t.CustomerId == custId); if (check == null) { Console.WriteLine("You have not placed any order yet !!"); } else { try { foreach (var t in orderList) { Console.WriteLine("\tCustomer Id : " + t.CustomerId + "\tToy Id: " + t.ToyId + "\tToy Quantity : " + t.ToyQuantity + "\tProduct Price : " + t.TotalAmount); } } catch (Exception e) { Console.WriteLine(e); } } } void ToyList() { var db = new CompanyDbEntities(); var toyList = db.Toys; try { foreach (var t in toyList) { Console.WriteLine("\tId: " + t.ToyId + "\tName : " + t.ToyName + "\tPrice: " + t.Price + "\tDescription :" + t.Description); } } catch (Exception e) { Console.WriteLine(e); } } void CustomerList() { var db = new CompanyDbEntities(); var customerList = db.Customers; try { foreach (var p in customerList) { Console.WriteLine("\tId: " + p.CustomerId + "\tName : " + p.Name + "\tContact No: " + p.ContactNo); } } catch (Exception e) { Console.WriteLine(e); } } void PlantList() { var db = new CompanyDbEntities(); var plantList = db.Plants; try { foreach (var p in plantList) { Console.WriteLine("\tId: " + p.PlantId + "\tName : " + p.PlantName); } } catch (Exception e) { Console.WriteLine(e); } } }
public DepartmentsController() { _db = new CompanyDbEntities(); }