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));
        }
        //
        // 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));
            }
        }
Esempio n. 3
0
        public void EditGet_CanEdit_ValidEmployeeIDSearchStruingEmpty()
        {
            // 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.Edit(5) as ViewResult;
            RegistrationDateViewModel visaRegDate = (RegistrationDateViewModel)result.ViewData.Model;

            // Assert - check the result
            Assert.AreEqual("", result.ViewName);
            Assert.IsInstanceOf(typeof(ViewResult), result);
            Assert.IsNotNull(result.ViewData.Model);
            Assert.AreEqual(5, visaRegDate.EmployeeID);
            Assert.AreEqual("Daolson Ivan (daol) from RAAA4", result.ViewBag.EmployeeInformation);
            Assert.AreEqual("", result.ViewBag.SearchString);
            Assert.AreEqual("dd.mm.yyyy", result.ViewBag.JSDatePattern);
        }