public ActionResult Create() { var customerList = this.session.QueryOver<Customer>() .OrderBy(x => x.Name) .Asc .List(); ViewBag.SelectCustomerList = new SelectList(customerList, "Id", "Name"); var model = new DailyReportViewModel(); return View(model); }
public ActionResult Create(DailyReportViewModel dailyReportViewModel) { if (ModelState.IsValid) { var customer = this.session.Load<Customer>(dailyReportViewModel.CustomerId); var dailyReport = new DailyReport { Customer = customer, Date = dailyReportViewModel.Date, AfternoonEnd = dailyReportViewModel.AfternoonEnd ?? string.Empty, AfternoonStart = dailyReportViewModel.AfternoonStart ?? string.Empty, MorningEnd = dailyReportViewModel.MorningEnd ?? string.Empty, MorningStart = dailyReportViewModel.MorningStart ?? string.Empty, Notes = dailyReportViewModel.Notes ?? string.Empty, Offsite = dailyReportViewModel.Offsite }; this.session.Save(dailyReport); return RedirectToAction("ManageReport", new {id = dailyReport.Id}); } return View(dailyReportViewModel); }
public ActionResult Edit(int id, DailyReportViewModel model) { if (ModelState.IsValid) { return RedirectToAction("Index"); } return View(); }
public void CreatingANewReport_AddsItToTheDb() { var controller = new DailyReportsController(this.session); string customerName = "Pippo1"; this.session.Save(new Customer { Name = customerName, VATNumber = "12345678901" }); var reportDate = new DateTime(2012, 11, 29, 8, 0, 0); var viewModel = new DailyReportViewModel { CustomerId = 1, Date = reportDate, MorningStart = "09:00", MorningEnd = "13:00", AfternoonStart = "14:00", AfternoonEnd = "18:00", Offsite = true, Notes = "La macchinetta del caffé fa pena." }; var result = controller.Create(viewModel); var redirectResult = result as RedirectToRouteResult; var action = redirectResult.RouteValues["action"]; var reportOnDb = this.session.Get<DailyReport>(1); reportOnDb.Should().Not.Be.Null(); reportOnDb.Customer.Should().Not.Be.Null(); reportOnDb.Customer.Name.Should().Be.EqualTo(customerName); reportOnDb.Date.Should().Be.EqualTo(reportDate); }