public ActionResult Create(VisaRegistrationDate visaRegDate, string searchString = "") { ViewBag.SearchString = searchString; ViewBag.JSDatePattern = MvcApplication.JSDatePattern; if (ModelState.IsValid) { try { repository.SaveVisaRegistrationDate(visaRegDate, visaRegDate.EmployeeID); } catch (System.InvalidOperationException) { return(Json(new { error = ModelError })); } List <Employee> empList = GetEmployeeData(repository.Employees.ToList(), searchString); Employee author = repository.Employees.Where(e => e.EID == HttpContext.User.Identity.Name).FirstOrDefault(); Employee empWithVisa = (from emp in repository.Employees where emp.EmployeeID == visaRegDate.EmployeeID select emp).FirstOrDefault(); messenger.Notify(new Message(MessageType.BTMCreateVisaRegistrationDateToEMP, null, author, empWithVisa)); return(View("TableViewVisasAndPermitsBTM", empList)); } RegistrationDateViewModel visaRegistrationDate = new RegistrationDateViewModel(visaRegDate); return(View(visaRegistrationDate)); }
public void SaveVisaRegistrationDate(VisaRegistrationDate visaRegistrationDate, int id) { VisaRegistrationDate dbEntry = (from vrd in context.VisaRegistrationDates where vrd.EmployeeID == visaRegistrationDate.EmployeeID select vrd).FirstOrDefault(); if (dbEntry != null && visaRegistrationDate.RowVersion != null) { if (!dbEntry.RowVersion.SequenceEqual(visaRegistrationDate.RowVersion)) { throw new DbUpdateConcurrencyException(); } dbEntry.EmployeeID = visaRegistrationDate.EmployeeID; dbEntry.VisaType = visaRegistrationDate.VisaType; dbEntry.RegistrationDate = visaRegistrationDate.RegistrationDate; dbEntry.City = visaRegistrationDate.City; dbEntry.RegistrationNumber = visaRegistrationDate.RegistrationNumber; dbEntry.RegistrationTime = visaRegistrationDate.RegistrationTime; } else { Employee employee = Employees.Where(e => e.EmployeeID == id).SingleOrDefault(); context.VisaRegistrationDates.Add(visaRegistrationDate); } context.SaveChanges(); }
public RegistrationDateViewModel(VisaRegistrationDate visaRegistrationDate) { EmployeeID = visaRegistrationDate.EmployeeID; VisaType = visaRegistrationDate.VisaType; RegistrationDate = string.Format("{0:d}", visaRegistrationDate.RegistrationDate); RegistrationTime = visaRegistrationDate.RegistrationTime; City = visaRegistrationDate.City; RegistrationNumber = visaRegistrationDate.RegistrationNumber; RowVersion = visaRegistrationDate.RowVersion; }
public VisaRegistrationDate DeleteVisaRegistrationDate(int employeeID) { VisaRegistrationDate dbEntry = context.VisaRegistrationDates.Where(vrd => vrd.EmployeeID == employeeID).SingleOrDefault(); if (dbEntry != null) { context.VisaRegistrationDates.Remove(dbEntry); context.SaveChanges(); } return(dbEntry); }
public VisaRegistrationDate DeleteVisaRegistrationDate(int employeeID) { VisaRegistrationDate dbEntry = visaRegistrationDates.Where(vrd => vrd.EmployeeID == employeeID).SingleOrDefault(); if (dbEntry != null) { dbEntry.VisaRegistrationDateOf.VisaRegistrationDate = null; visaRegistrationDates.Remove(dbEntry); } return(dbEntry); }
public void EditGet_CannotEdit_InvalidEmployeeID() { // Arrange - create the controller VisaRegistrationDateController target = new VisaRegistrationDateController(mock.Object, messengerMock.Object); // Act - call the action method var result = (HttpNotFoundResult)target.Edit(15); VisaRegistrationDate visaRegDate = mock.Object.VisaRegistrationDates.Where(m => m.EmployeeID == 15).FirstOrDefault(); // Assert - check the result Assert.IsInstanceOf(typeof(HttpNotFoundResult), result); Assert.AreEqual(404, result.StatusCode); Assert.IsNull(visaRegDate); }
public void CustomDisplayCityOfVisaRegistration_ValidVisaRegDateCityisNull_FormattedString() { //Arrange var vc = new ViewContext(); vc.HttpContext = new FakeHttpContext(); HtmlHelper helper = new HtmlHelper(vc, new FakeViewDataContainer()); VisaRegistrationDate visaRegistrationDate = new VisaRegistrationDate(); //Act string result = helper.CustomDisplayCityOfVisaRegistration(visaRegistrationDate).ToString(); //Assert Assert.AreEqual("City is not specified", result); }
public void CreatePost_CannotCreate_InvalidVisaRegistrationDate() { // Arrange - create the controller VisaRegistrationDateController target = new VisaRegistrationDateController(mock.Object, messengerMock.Object); VisaRegistrationDate visaRegDate = new VisaRegistrationDate(); // Act - call the action method target.ModelState.AddModelError("error", "error"); ViewResult result = target.Create(visaRegDate) as ViewResult; // Assert - check the result mock.Verify(m => m.SaveVisaRegistrationDate(It.IsAny <VisaRegistrationDate>(), It.IsAny <int>()), Times.Never); Assert.IsInstanceOf(typeof(RegistrationDateViewModel), result.ViewData.Model); Assert.IsInstanceOf(typeof(ViewResult), result); }
public void CustomDisplayVisaRegistrationDateForEMP_DateISNull_EmptyString() { //Arrange var vc = new ViewContext(); vc.HttpContext = new FakeHttpContext(); HtmlHelper helper = new HtmlHelper(vc, new FakeViewDataContainer()); //Act VisaRegistrationDate visaRegDate = mock.Object.VisaRegistrationDates.Where(r => r.EmployeeID == 6).FirstOrDefault(); MvcHtmlString result = helper.CustomDisplayVisaRegistrationDateForEMP(visaRegDate); MvcHtmlString expected = new MvcHtmlString(""); //Assert Assert.AreEqual(expected.ToString(), result.ToString()); }
public void EditPost_CannotEdit_InvalidVisaRegistrationDate() { // Arrange - create the controller VisaRegistrationDateController target = new VisaRegistrationDateController(mock.Object, messengerMock.Object); VisaRegistrationDate visaRegDate = new VisaRegistrationDate(); // Act - call the action method target.ModelState.AddModelError("error", "error"); var result = target.Edit(visaRegDate); // Assert - check the result mock.Verify(m => m.SaveVisaRegistrationDate(visaRegDate, 1), Times.Never); Assert.IsInstanceOf(typeof(ViewResult), result); Assert.AreEqual("", ((ViewResult)result).ViewName); Assert.IsInstanceOf(typeof(RegistrationDateViewModel), ((ViewResult)result).ViewData.Model); }
public void CreateGet_VisaRegistrationDateOf_ExistingEmployeeSearchStringEmpty() { // Arrange - create the controller VisaRegistrationDateController target = new VisaRegistrationDateController(mock.Object, messengerMock.Object); MvcApplication.JSDatePattern = "dd.mm.yyyy"; // Act - call the action method var result = target.Create(5) as ViewResult; VisaRegistrationDate visaRegDate = (VisaRegistrationDate)result.ViewData.Model; // Assert - check the result Assert.AreEqual("", result.ViewName); Assert.AreEqual("", result.ViewBag.SearchString); Assert.AreEqual("dd.mm.yyyy", result.ViewBag.JSDatePattern); Assert.IsInstanceOf(typeof(ViewResult), result); Assert.AreEqual("Daolson Ivan (daol) from RAAA4", result.ViewBag.EmployeeInformation); Assert.IsNull(visaRegDate); }
public void CustomDisplayCityOfVisaRegistration_CityIsNotSpecified_EmptyStrind() { //Arrange var vc = new ViewContext(); vc.HttpContext = new FakeHttpContext(); HtmlHelper helper = new HtmlHelper(vc, new FakeViewDataContainer()); // var emp = mock.Object.Employees.Where(e => e.EmployeeID == 1).LastOrDefault(); VisaRegistrationDate visaRegistrationDate = new VisaRegistrationDate() { City = "" }; //Act string result = helper.CustomDisplayCityOfVisaRegistration(visaRegistrationDate).ToString(); //Assert Assert.AreEqual("City is not specified", result); }
public void SaveVisaRegistrationDate(VisaRegistrationDate visaRegistrationDate, int id) { VisaRegistrationDate dbEntry = (from vrd in VisaRegistrationDates where vrd.EmployeeID == visaRegistrationDate.EmployeeID select vrd).FirstOrDefault(); if (dbEntry != null) { dbEntry.EmployeeID = visaRegistrationDate.EmployeeID; dbEntry.VisaType = visaRegistrationDate.VisaType; dbEntry.RegistrationDate = visaRegistrationDate.RegistrationDate; } else { Employee employee = Employees.Where(e => e.EmployeeID == id).SingleOrDefault(); visaRegistrationDate.VisaRegistrationDateOf = employee; visaRegistrationDate.EmployeeID = employee.EmployeeID; visaRegistrationDate.VisaRegistrationDateOf.VisaRegistrationDate = visaRegistrationDate; visaRegistrationDates.Add(visaRegistrationDate); } }
public ActionResult DeleteConfirmed(int id, string searchString = "") { VisaRegistrationDate visaRegistrationDate = (from v in repository.VisaRegistrationDates where v.EmployeeID == id select v).FirstOrDefault(); ViewBag.SearchString = searchString; ViewBag.JSDatePattern = MvcApplication.JSDatePattern; if (visaRegistrationDate == null) { return(HttpNotFound()); } else { repository.DeleteVisaRegistrationDate(id); List <Employee> empList = GetEmployeeData(repository.Employees.ToList(), searchString); return(View("TableViewVisasAndPermitsBTM", empList)); } //return RedirectToAction("BTMView", "Home", new { searchString = searchString }); }
public void EditPost_ValidModelConcurrency_ErrorReturned() { //Arrange VisaRegistrationDateController controller = new VisaRegistrationDateController(mock.Object, messengerMock.Object); string modelError = "The record you attempted to edit " + "was modified by another user after you got the original value. The " + "edit operation was canceled."; VisaRegistrationDate visaRegDate = mock.Object.VisaRegistrationDates.Where(p => p.EmployeeID == 1).FirstOrDefault(); mock.Setup(m => m.SaveVisaRegistrationDate(visaRegDate, visaRegDate.EmployeeID)).Throws(new DbUpdateConcurrencyException()); //Act var result = controller.Edit(visaRegDate); string data = (string)(new Microsoft.VisualStudio.TestTools.UnitTesting.PrivateObject(((JsonResult)result).Data, "error")).Target; //Assert mock.Verify(d => d.SaveVisaRegistrationDate(visaRegDate, visaRegDate.EmployeeID), Times.Once()); Assert.AreEqual(typeof(JsonResult), result.GetType()); Assert.AreEqual(modelError, data); }
// // GET: /VisaRegistrationDate/Edit/5 public ActionResult Edit(int id = 0, string searchString = "") { ViewBag.SearchString = searchString; ViewBag.JSDatePattern = MvcApplication.JSDatePattern; VisaRegistrationDate visaRegDate = (from v in repository.VisaRegistrationDates where v.EmployeeID == id select v).FirstOrDefault(); if (visaRegDate == null) { return(HttpNotFound()); } else { ViewBag.EmployeeInformation = visaRegDate.VisaRegistrationDateOf.LastName + " " + visaRegDate.VisaRegistrationDateOf.FirstName + " (" + visaRegDate.VisaRegistrationDateOf.EID + ") from " + visaRegDate.VisaRegistrationDateOf.Department.DepartmentName; ViewBag.EmployeeID = id; RegistrationDateViewModel visaRegistrationDate = new RegistrationDateViewModel(visaRegDate); return(View(visaRegistrationDate)); } }
public void EditPost_CanEdit_ValidVisaRegistrationDate() { // Arrange - create the controller VisaRegistrationDateController target = new VisaRegistrationDateController(mock.Object, messengerMock.Object); VisaRegistrationDate visaRegDate = new VisaRegistrationDate { EmployeeID = 5, RegistrationDate = new DateTime(2013, 04, 01), VisaType = "D10" }; MvcApplication.JSDatePattern = "dd.mm.yyyy"; target.ControllerContext = controllerContext.Object; // Act - call the action method var result = target.Edit(visaRegDate); // Assert - check the result mock.Verify(m => m.SaveVisaRegistrationDate(visaRegDate, 5), Times.Once); Assert.AreEqual("TableViewVisasAndPermitsBTM", ((ViewResult)result).ViewName); Assert.IsInstanceOf(typeof(List <Employee>), ((ViewResult)result).Model); Assert.AreEqual("", ((ViewResult)result).ViewBag.SearchString); Assert.AreEqual("dd.mm.yyyy", ((ViewResult)result).ViewBag.JSDatePattern); }
public static MvcHtmlString CustomDisplayVisaRegistrationDateForEMP(this HtmlHelper helper, VisaRegistrationDate visaRegDate) { StringBuilder builder = new StringBuilder(""); if (visaRegDate == null || visaRegDate.RegistrationDate == default(DateTime)) { builder.Append(""); } else { if (visaRegDate.RegistrationDate.HasValue) { builder.AppendFormat("<tr><td rowspan=\"4\"><b>Visa Registration Date</b></td> <td><customBlueItalic>Date: </customBlueItalic> {0:dd.MM.yyyy} </td></tr> <br />", visaRegDate.RegistrationDate.Value.Date); } if (visaRegDate.RegistrationTime == null || visaRegDate.RegistrationTime == "") { builder.AppendFormat("<tr><td><customBlueItalic>Time:</customBlueItalic> - </td></tr>"); } else { builder.AppendFormat("<tr><td><customBlueItalic>Time:</customBlueItalic> {0}</td></tr>", visaRegDate.RegistrationTime); } if (visaRegDate.City == null || visaRegDate.City == "") { builder.AppendFormat("<tr><td><customBlueItalic>City:</customBlueItalic> - </td></tr>"); } else { builder.AppendFormat("<tr><td><customBlueItalic>City:</customBlueItalic> {0}</td></tr>", visaRegDate.City); } if (visaRegDate.RegistrationNumber == null || visaRegDate.RegistrationNumber == "") { builder.AppendFormat("<tr><td><customBlueItalic>Registration Number:</customBlueItalic> - </td> </tr>"); } else { builder.AppendFormat("<tr><td><customBlueItalic>Registration Number:</customBlueItalic> {0}</td> <td> <br /> </td> </tr>", visaRegDate.RegistrationNumber); } builder.Append("<tr> <td><br/></td> </tr>"); } return(new MvcHtmlString(builder.ToString())); }
public static MvcHtmlString CustomDisplayCityOfVisaRegistration(this HtmlHelper helper, VisaRegistrationDate visaRegistrationDate) { if (visaRegistrationDate != null) { if (visaRegistrationDate.City != null && visaRegistrationDate.City != String.Empty) { return(new MvcHtmlString(String.Format("{0}", visaRegistrationDate.City))); } else { return(new MvcHtmlString("City is not specified")); } } return(new MvcHtmlString("")); }