public ActionResult Create(CreateOrEditCustomerViewModel newCustomer) { var existing = this.session.QueryOver<Customer>() .Where(x => x.VATNumber == newCustomer.VATNumber) .SingleOrDefault(); if (existing != null) ModelState.AddModelError("VATNumber", "Un cliente con stessa partita Iva è già presente."); if (ModelState.IsValid) { var customer = new Customer { Name = newCustomer.Name, VATNumber = newCustomer.VATNumber }; this.session.Save(customer); return RedirectToAction("Index"); } return View(newCustomer); }
public void AddingANewActvity_PutsItInTheDb() { var controller = new DailyReportsController(this.session); string customerName = "Pippo1"; var customer = new Customer {Name = customerName, VATNumber = "12345678901"}; this.session.Save(customer); var dailyReport = new DailyReport { Customer = customer, MorningStart = "09:00", MorningEnd = "13:00", AfternoonStart = "14:00", AfternoonEnd = "18:00", Date = new DateTime(2012,12,11) }; this.session.Save(dailyReport); var result = controller.ManageReport(1, new ActivityViewModel { Description = "Corso Asp.Net Mvc", Hours = 4m }); this.session.Flush(); var redirectResult = result as RedirectToRouteResult; var action = redirectResult.RouteValues["action"]; action.Should().Be.EqualTo("ManageReport"); var activityOnDb = this.session.Get<Activity>(1); activityOnDb.Should().Not.Be.Null(); }