private void Seed() { // Create a couple of Stores each with some Products and Employees var barginBasin = new Store { Name = "Bargin Basin" }; var superMart = new Store { Name = "SuperMart" }; var potatoes = new Product { Name = "Potatoes", Price = 3.60 }; var fish = new Product { Name = "Fish", Price = 4.49 }; var milk = new Product { Name = "Milk", Price = 0.79 }; var bread = new Product { Name = "Bread", Price = 1.29 }; var cheese = new Product { Name = "Cheese", Price = 2.10 }; var waffles = new Product { Name = "Waffles", Price = 2.41 }; var daisy = new Employee { FirstName = "Daisy", LastName = "Harrison" }; var jack = new Employee { FirstName = "Jack", LastName = "Torrance" }; var sue = new Employee { FirstName = "Sue", LastName = "Walkters" }; var bill = new Employee { FirstName = "Bill", LastName = "Taft" }; var joan = new Employee { FirstName = "Joan", LastName = "Pope" }; // Add Products to the Stores // The Store-Product relationship is many-to-many AddProductsToStore(barginBasin, potatoes, fish, milk, bread, cheese); AddProductsToStore(superMart, bread, cheese, waffles); // Add Employees to the Stores // The Store-Employee relationship is one-to-many AddEmployeesToStore(barginBasin, daisy, jack, sue); AddEmployeesToStore(superMart, bill, joan); StoreRepository.SaveOrUpdateAll(barginBasin, superMart); }
public virtual void AddEmployee(Employee employee) { employee.Store = this; Staff.Add(employee); }
private EmployeeEditModel EmployeeToEditModel(Employee employee) { EmployeeEditModel employeeEditModel = new EmployeeEditModel(); employeeEditModel.ImagePath = employee.ImagePath; employeeEditModel.FirstName = employee.FirstName; employeeEditModel.LastName = employee.LastName; employeeEditModel.HtmlBanner = HttpUtility.HtmlDecode(employee.HtmlBanner); employeeEditModel.HtmlDetail = HttpUtility.HtmlDecode(employee.HtmlDetail); employeeEditModel.HtmlBannerEdit = HttpUtility.HtmlDecode(employee.HtmlBannerEdit); employeeEditModel.Email = employee.Email; employeeEditModel.Id = employee.Id; employeeEditModel.Products = ProductsRepository.Get(p => p.Employee.Id == employee.Id).ToList(); return employeeEditModel; }
public ActionResult Create(int userId) { User user = UserRepository.Get(u => u.UserName == User.Identity.Name).SingleOrDefault(); User userauthor = UserRepository.Get(u => u.Id == userId).SingleOrDefault(); if (user != null && user.Role.IsAdmin && userauthor != null) { userauthor.Role.IsAuthor = true; Employee employee = new Employee(); employee.Email = user.Email; employee.FirstName = "Ім'я"; employee.LastName = "Прізвище"; employee.ImagePath = DefaulImg; Employee employeeSaved = EmployeeRepository.SaveOrUpdate(employee); employee.HtmlBannerEdit = Server.HtmlEncode(string.Format(_authorEdit, employeeSaved.Id, DefaulImg, employee.FirstName, employee.LastName, employee.Email)); employee.HtmlBanner = Server.HtmlEncode(string.Format(_authorTemplate, employeeSaved.Id, DefaulImg, employee.FirstName, employee.LastName, user.Email)); userauthor.Employee = employeeSaved; UserRepository.SaveOrUpdate(userauthor); return RedirectToAction("Edit", "Employee", new { id = employeeSaved.Id }); } return null; }