public void OfficeRepository_AddOffice_Added_NotFail_Test() { var context = new MyCompanyContext(); int expected = context.Offices.Count() + 1; var target = new OfficeRepository(context); var officeId = context.Offices.Select(e => e.OfficeId).Max() + 1; var calendarId = context.Calendars.FirstOrDefault().CalendarId; var office = new Office() { OfficeId = officeId, CalendarId = calendarId }; target.Add(office); int actual = context.Offices.Count(); Assert.AreEqual(expected, actual); target.Delete(officeId); actual = context.Offices.Count(); Assert.AreEqual(expected - 1, actual); }
public IActionResult Create(Office model) { if (HttpContext.Session.GetString("ID") == null) { return(RedirectToAction("Login", "Admin")); } else { if (ModelState.IsValid) { bool check = officeRepository.checkID(model.ID); if (check) { officeRepository.Add(model); return(RedirectToAction("Index")); } else { ViewBag.listAllCities = officeRepository.listAllCities(); ModelState.AddModelError(string.Empty, "This ID already exists."); return(View()); } } ViewBag.listAllCities = officeRepository.listAllCities(); return(View(model)); } }
///<inheritdoc/> public override void Handle(BrokeredMessage message) { var officeRepository = new OfficeRepository(new MyCompanyContext()); var dto = message.GetBody <OfficeDTO>(); var office = Mapper.Map <Office>(dto); officeRepository.Add(office); }