private void CheckInitialOptions(UserDateModel model) { if (model.AllUsersSelected == false && model.AllEmployedUsersSelected == false && model.UserName == null) { ModelState.AddModelError("", "Wpisz login"); } }
private FileStreamResult GenerateFileForDownload(UserDateModel model) { Stream stream = excelGenerator.GenerateStreamFromTemplate(model.Timetables); FileStreamResult result = new FileStreamResult(stream, System.Net.Mime.MediaTypeNames.Application.Octet); result.FileDownloadName = "Karty_czasu_pracy.xlsx"; return(result); }
public void returns_file_when_excel_clicked() { Fixture fixture = new Fixture(); HomeController homeController = fixture.GetMockController(); UserDateModel model = fixture.GetModel(); ActionResult result = homeController.Index(null, null, "", model); Assert.IsInstanceOf <FileStreamResult>(result); }
public void returns_index_when_model_not_valid() { Fixture fixture = new Fixture(); HomeController homeController = fixture.GetMockController(); var model = new UserDateModel(); ActionResult result = homeController.Index(null, null, "", model); Assert.IsInstanceOf <ViewResult>(result); ((ViewResult)result).ViewName.Should().Be(""); }
public void returns_print_when_drukuj_clicked() { Fixture fixture = new Fixture(); HomeController homeController = fixture.GetMockController(); UserDateModel model = fixture.GetModel(); ActionResult result = homeController.Index(null, "", null, model); Assert.IsInstanceOf <ViewResult>(result); ((ViewResult)result).ViewName.Should().Be("Print"); }
internal UserDateModel GetModel() { var model = new UserDateModel(); model.SelectedMonth = 1; model.UserName = "******"; model.SelectedYear = 2; model.AllUsersSelected = false; return(model); }
private void GenerateTimetable(UserDateModel model) { if (model.AllUsersSelected) { GenerateTimetableForAllUsers(model); } else if (model.AllEmployedUsersSelected) { GenerateTimetableForAllEmployedUsers(model); } else { GenerateTimetableForSpecifcUser(model); } }
private void GenerateTimetableForAllEmployedUsers(UserDateModel model) { model.Timetables = provider.GetTimetableForAllEmployedWorkers(model.SelectedMonth, model.SelectedYear); }
public ActionResult Index(string ShowButton, string PrintButton, string ExcelButton, UserDateModel model) { CheckInitialOptions(model); if (!ModelState.IsValid) { return(View(model)); } try { GenerateTimetable(model); } catch (NoWorkerException) { ModelState.AddModelError("", "Nie ma takiego pracownika"); return(View(model)); } if (PrintButton != null) { return(View("Print", model.Timetables)); } if (ExcelButton != null) { return(GenerateFileForDownload(model)); } return(View(model)); }
// GET: Home public ViewResult Index() { UserDateModel model = new UserDateModel(dateProvider); return(View(model)); }
private void GenerateTimetableForSpecifcUser(UserDateModel model) { model.Timetables = new List <Timetable> { provider.GetTimetableForSpecificWorker(model.UserName, model.SelectedMonth, model.SelectedYear) }; }