public void AddError_ArgsWithProperty_CreatesAndAddsCorrectError() { var item = new EmployeeVM(); var owner = new EmployeeListVM(item); var validator = Mock <IValidator>(); var step = ValidationStep.Value; var message = "Test error message"; var details = new Object(); var args = CreateArgsWithProperty(owner, step, validator); args.AddError(item, message, details); var expectedError = new ValidationError( validator, ValidationTarget.ForError( step, item, owner.GetValue(x => x.Employees), EmployeeVM.ClassDescriptor.Name ), message, details ); ValidationAssert.HasErrors(args.Result, ValidationAssert.FullErrorComparer, expectedError); }
public void TestMethod1() { IEnumerable <Employee> source = GenerateEmployees(); var list = new EmployeeListVM(); var sw = Stopwatch.StartNew(); list = new EmployeeListVM(); list.Source = source; list.Revalidate(ValidationScope.SelfAndLoadedDescendants); foreach (EmployeeVM item in list.GetValue(x => x.Employees)) { var selection = item.GetValue(x => x.EmploymentType); object simulatedBindingAccess = item.GetValue(x => x.Name); simulatedBindingAccess = selection.GetValue(x => x.AllItems); simulatedBindingAccess = selection.GetValue(x => x.SelectedItem); } //sw.Stop(); //Console.WriteLine("Time [ms]: " + sw.ElapsedMilliseconds); //sw = Stopwatch.StartNew(); //list.Revalidate(ValidationScope.SelfAndAllDescendants); sw.Stop(); Console.WriteLine("Time [ms]: " + sw.ElapsedMilliseconds); }
public ActionResult Index() { Employee emp = new Employee(); emp.FirstName = "Sathish"; emp.LastName = "Tammalla"; emp.Salary = 100000; // ViewData["Employee"] = emp; //ViewBag.Employee = emp; EmployeVM vm = new EmployeVM(); vm.EmployeeName = emp.FirstName + " " + emp.LastName; vm.UserName = "******"; vm.SalaryColor = "blue"; vm.Salary = Convert.ToString(emp.Salary); EmployeeListVM empListView = new EmployeeListVM(); empListView.UserName = User.Identity.Name; EmployeeBusinessLayer ebl = new EmployeeBusinessLayer(); List <Employee> employees = new List <Employee>(); employees = ebl.GetEmployees(); List <EmployeVM> employeeVMs = new List <EmployeVM>(); foreach (Employee empl in employees) { EmployeVM emplVM = new EmployeVM(); emplVM.EmployeeName = empl.FirstName + " " + empl.LastName; emplVM.Salary = Convert.ToString(empl.Salary); if (empl.Salary > 10000 && empl.Salary <= 20000) { emplVM.SalaryColor = "blue"; } else if (empl.Salary > 20000 && empl.Salary <= 30000) { emplVM.SalaryColor = "green"; } else { emplVM.SalaryColor = "yellow"; } employeeVMs.Add(emplVM); } empListView.Employees = employeeVMs; empListView.FooterData = new FooterVM(); // empListView.Footer.CompanyName = "Sathish MVC Tutorial"; empListView.FooterData.CompanyName = "Sathish MVC Tutorial"; empListView.FooterData.Year = DateTime.Now.Year.ToString(); empListView.FooterData.Terms = "All Rights are Reserved!"; empListView.UserName = HttpContext.User.Identity.Name; // empListView.UserName = empListView.I; return(View("Index", empListView)); }
public void Create_PathWithViewModelPlusCollection_SetPropertiesCorrectly() { var owner = new EmployeeListVM(); var args = CreateArgs(owner); Assert.AreEqual(owner, args.Owner); Assert.AreEqual(owner.GetValue(x => x.Employees), args.Items); }
public void Create_PathWithViewModelPlusCollectionPlusProperty_SetPropertiesCorrectly() { var owner = new EmployeeListVM(); var args = CreateArgsWithProperty(owner); Assert.AreEqual(owner, args.Owner); Assert.AreEqual(owner.GetValue(x => x.Employees), args.Items); Assert.AreEqual(EmployeeVM.ClassDescriptor.Name, args.TargetProperty); }
// GET: ViewTimesheet public ActionResult Index() { var empRepo = new EmployeeDatabase(); var input = new EmployeeListVM(); input.EmployeeList = new SelectList(empRepo.GetAll(), "Id", "Name"); return View(input); }
public ActionResult Details(int id) { ViewData["DateTime"] = DateTime.Now; ViewBag.Date = DateTime.Now.DayOfWeek; var val = RouteData.Values["id"]; EmployeeListVM empList = new EmployeeListVM(); var model = empList.EmployeeList.FirstOrDefault(item => item.Id == id); return(View(model)); }
public void Setup() { InvalidItemsOfCollectionValidator = new List <EmployeeVM>(); InvalidItemsOfSecondCollectionValidator = new List <EmployeeVM>(); InvalidItemsOfPropertyValidator = new List <EmployeeVM>(); InvalidItemsOfSecondPropertyValidator = new List <EmployeeVM>(); VM = new EmployeeListVM(this); TargetItem = new EmployeeVM(this, "Target employee"); OtherItem = new EmployeeVM(this, "Other employee"); VM.GetValue(x => x.Employees).Add(TargetItem); VM.GetValue(x => x.Employees).Add(OtherItem); }
private static CollectionValidationArgs <IViewModel, EmployeeVM> CreateArgs( EmployeeListVM owner, IValidator validator = null ) { validator = validator ?? Mock <IValidator>(); var path = Path.Empty .Append(owner) .Append(owner.GetValue(x => x.Employees)); return(CollectionValidationArgs <IViewModel, EmployeeVM> .Create( validator, new ValidationRequest(ValidationStep.ViewModel, path) )); }
private static CollectionValidationArgs <IViewModel, EmployeeVM, string> CreateArgsWithProperty( EmployeeListVM owner, ValidationStep step = ValidationStep.Value, IValidator validator = null ) { validator = validator ?? Mock <IValidator>(); var path = Path.Empty .Append(owner) .Append(owner.GetValue(x => x.Employees)) .Append(EmployeeVM.ClassDescriptor.Name); return(CollectionValidationArgs <IViewModel, EmployeeVM, string> .Create( validator, new ValidationRequest(step, path) )); }
// GET: Employee public ActionResult Index() { /* original code * var employees = db.Employees.Include(e => e.Restaurants); * return View(employees.ToList()); */ var vm = new EmployeeListVM { VmEmployees = db.Employees.Select(x => new EmployeeVM { EmpID = x.EmpID, Name = x.Name, PayRate = x.PayRate, BaseHours = x.BaseHours, isManager = x.isManager, RestaurantName = x.Restaurants.Name }) }; return(View("Index", vm)); }
// GET: Employee public ActionResult Index() { EmployeeListVM empList = new EmployeeListVM(); return(View(empList.EmployeeList)); }
public EmployeeListView(EmployeeListVM vm) { InitializeComponent(); ViewModel = vm; }
public void CollectionValidation_DefinedForDerivedItem_Success() { var listVM = new EmployeeListVM(); listVM.Initialize(); }
//[HeaderFooterFilter] public ActionResult Index(int?page, string searchString, string sortOrder) { int pageSize = 5; int pageIndex = 1; pageIndex = page.HasValue ? Convert.ToInt32(page) : 1; IPagedList <EmployeeVM> empPList = null; ViewBag.NameSortParm = String.IsNullOrEmpty(sortOrder) ? "name_desc" : ""; ViewBag.DateSortParm = sortOrder == "Date" ? "date_desc" : "Date"; bool IsAdmin = false; if (User.Identity.Name == "admin") { IsAdmin = true; Session["IsAdmin"] = IsAdmin; } EmployeeListVM emplListVM = new EmployeeListVM(); List <EmployeeVM> employeeList = new List <EmployeeVM>(); List <Employee> employees = empBL.GetEmployees(); IEnumerable <Employee> emps = employees; if (!String.IsNullOrEmpty(searchString)) { emps = employees.Where(s => s.FirstName.Contains(searchString) || s.LastName.Contains(searchString)); } switch (sortOrder) { case "name_desc": emps = emps.OrderByDescending(s => s.FirstName); break; case "Date": emps = emps.OrderBy(s => s.EnrollmentDate); break; case "date_desc": emps = emps.OrderByDescending(s => s.EnrollmentDate); break; default: emps = emps.OrderBy(s => s.FirstName); break; } foreach (Employee employee in emps) { EmployeeVM empVM = new EmployeeVM(); empVM.EmpName = employee.FirstName + " " + employee.LastName; empVM.EmployeeId = employee.EmployeeId; empVM.Age = employee.Age.ToString(); empVM.EnrollmentDate = employee.EnrollmentDate; employeeList.Add(empVM); } emplListVM.Employees = employeeList as IPagedList <EmployeeVM>; empPList = employeeList.ToPagedList(pageIndex, pageSize); return(View("Index", empPList)); }
public ActionResult Index(EmployeeListVM input) { return RedirectToAction("SummaryPage", new {id = input.EmployeeId}); }