Beispiel #1
0
        private void ShowEditDepartment()
        {
            var departmentDetailsViewModel = new DepartmentDetailsViewModel(_selectedItems);
            var message = new GenericMessageWithCallback <DepartmentDetailsViewModel>(departmentDetailsViewModel, FillGrid);

            Messenger.Default.Send(message);
        }
        /*
         * Author:     Daniel Figueroa
         * Purpose:    Queries for the first item in Department and Employee table to build DepartmentIndexViewModel to test
         *          against DepartmentIndexContentVerfied
         */
        private async Task <DepartmentDetailsViewModel> GetFullDepartmentDetails(int id)
        {
            using (IDbConnection conn = new SqlConnection(Config.ConnectionString))
            {
                DepartmentDetailsViewModel placeholder = new DepartmentDetailsViewModel();
                string sql = $@"
                    SELECT
                        d.Id,
                        d.Name,
                        d.Budget,
                        e.Id, 
                        e.FirstName,
                        e.LastName, 
                        e.IsSupervisor,
                        e.DepartmentId
                    FROM Department d
                    LEFT OUTER JOIN Employee e ON d.Id = e.DepartmentId
                    WHERE d.Id = {id}
                    ";
                IEnumerable <Department> departments = await conn.QueryAsync <Department, Employee, Department>(
                    sql,
                    (department, employee) =>
                {
                    placeholder.Department = department;
                    if (employee != null)
                    {
                        placeholder.AllEmployees.Add(employee);
                    }
                    return(department);
                });

                return(placeholder);
            }
        }
        public async Task <IActionResult> OnGetAsync(int departmentId)
        {
            try
            {
                DepartmentDetailsViewModel departmentDetailsViewModel = await _departmentService.GetDepartmentAsync(departmentId);

                if (departmentDetailsViewModel == null)
                {
                    return(NotFound());
                }

                UpdateDepartmentViewModel = new UpdateDepartmentViewModel()
                {
                    DepartmentId   = departmentDetailsViewModel.DepartmentId,
                    DepartmentName = departmentDetailsViewModel.DepartmentName,
                    Description    = departmentDetailsViewModel.Description,
                };
            }
            catch (Exception)
            {
                ErrorMessage = "There is some problem with the service. Please try again. If the problem persists then contract with the system administrator.";
            }

            return(Page());
        }
        public IActionResult All(int id)
        {
            DepartmentDetailsViewModel model = new DepartmentDetailsViewModel
            {
                Departments = _context.Departments.Include(d => d.Doctors).ToList(),
                //DoctorOpeningHourses = _context.DoctorsOpeningHours
                //.Include(d => d.Doctor).FirstOrDefault(),
                //Doctor = _context.Doctors.Include(d => d.DoctorOpeningHours).FirstOrDefault(),

                Department = _context.Departments.Include(d => d.Doctors)
                             .Where(d => d.Id == id)
                             .FirstOrDefault(),
                Clients    = _context.Clients.ToList(),
                BreadCrumb = new BreadCrumbViewModel
                {
                    Title = "Şöbələrimiz",
                    Links = new List <string>
                    {
                        "Ana Səhifə",
                        "Şöbələr"
                    }
                }
            };

            return(View(model));
        }
Beispiel #5
0
        public async Task <IActionResult> Details(string Id)
        {
            int decryptedId;
            int y;

            if (int.TryParse(Id, out y))
            {
                decryptedId = y;
            }
            else
            {
                decryptedId = Convert.ToInt32(protector.Unprotect(Id));
            }

            var department = await departmentService.GetDepartment(decryptedId);

            if (department == null)
            {
                return(View("NotFound", decryptedId));
            }
            if (Id == null)
            {
                return(RedirectToAction("Index"));
            }
            DepartmentDetailsViewModel departmentDetailsViewModel = new DepartmentDetailsViewModel
            {
                Department  = department,
                EncryptedId = Id,
                PageTitle   = "DEPARTMENT DETAILS"
            };

            return(View(departmentDetailsViewModel));
        }
        public async Task <IActionResult> Details(string id)
        {
            DepartmentDetailsViewModel department = (await departmentService.GetById(id))
                                                    .To <DepartmentDetailsViewModel>();

            return(View(department));
        }
Beispiel #7
0
		public void AddSameNameTest()
		{
			var organisation = new Organisation();
			var department = new ShortDepartment { Name = "Name", OrganisationUID = organisation.UID };
			var newDepartment = new ShortDepartment { Name = "Name", OrganisationUID = organisation.UID };
			var mock = new Mock<ISafeRubezhService>();
			mock.Setup(x => x.GetOrganisations(It.IsAny<OrganisationFilter>())).Returns<OrganisationFilter>(filter =>
			{
				return new OperationResult<List<Organisation>>(new List<Organisation> { organisation });
			});
			mock.Setup(x => x.GetDepartmentList(It.IsAny<DepartmentFilter>())).Returns<DepartmentFilter>(filter =>
			{
				return new OperationResult<List<ShortDepartment>>(new List<ShortDepartment> { department });
			});
			mock.Setup(x => x.GetDepartmentDetails(It.IsAny<Guid>())).Returns<Guid>(uid =>
			{
				if (uid == department.UID)
					return new OperationResult<Department>(new Department { UID = department.UID, OrganisationUID = department.UID, Name = department.Name });
				return null;
			});
			mock.Setup(x => x.GetEmployeeList(It.IsAny<EmployeeFilter>())).Returns(() =>
			{
				return new OperationResult<List<ShortEmployee>>();
			});
			ClientManager.RubezhService = mock.Object;
			
		
			var departmentsViewModel = new DepartmentsViewModel();
			departmentsViewModel.Initialize(new DepartmentFilter());
			var detailsViewModel = new DepartmentDetailsViewModel();
			detailsViewModel.Initialize(organisation, newDepartment, departmentsViewModel);
			Assert.IsFalse(detailsViewModel.ValidateAndSave());
		}
        public async Task Get_DepartmentDetailsContentVerified()
        {
            // Arrange
            DepartmentIndexViewModel   fullDepartment   = (await GetFullDepartment());
            DepartmentDetailsViewModel singleDepartment = (await GetFullDepartmentDetails(fullDepartment.Id));
            string url = $"/department/details/{singleDepartment.Department.Id}";

            // Act
            HttpResponseMessage response = await _client.GetAsync(url);

            // Assert
            response.EnsureSuccessStatusCode(); // Status Code 200-299
            Assert.Equal("text/html; charset=utf-8",
                         response.Content.Headers.ContentType.ToString());

            IHtmlDocument indexPage = await HtmlHelpers.GetDocumentAsync(response);

            Assert.Contains(indexPage.QuerySelectorAll("dd"),
                            dd => dd.TextContent.Contains(singleDepartment.Department.Name));
            Assert.Contains(indexPage.QuerySelectorAll("dd"),
                            dd => dd.TextContent.Contains(singleDepartment.Department.Budget.ToString()));
            if (singleDepartment.AllEmployees.Count == 0)
            {
                Assert.Contains(indexPage.QuerySelectorAll("li"),
                                li => li.TextContent.Contains("No Employees"));
            }
            else
            {
                Assert.Contains(indexPage.QuerySelectorAll("li"),
                                li => li.TextContent.Contains(singleDepartment.AllEmployees.First <Employee>().FirstName));
            }
        }
Beispiel #9
0
        public async Task <DepartmentDetailsViewModel> GetByIdAsync(int departmentId)
        {
            departmentId.ThrowIfNotPositive(nameof(departmentId));

            DepartmentDetailsViewModel response = await _httpClient.GetFromJsonAsync <DepartmentDetailsViewModel>($"v1/departments/{departmentId}");

            return(response);
        }
Beispiel #10
0
        public async Task <IActionResult> OnGetAsync(int departmentId)
        {
            DepartmentDetailsViewModel departmentDetailsViewModel = await _departmentService.GetDepartmentAsync(departmentId);

            if (departmentDetailsViewModel == null)
            {
                return(NotFound());
            }

            DepartmentDetailsViewModel = departmentDetailsViewModel;
            return(Page());
        }
        private async Task <IActionResult> SetDepartmentViewModelValueAsync(int departmentId)
        {
            DepartmentDetailsViewModel departmentDetailsViewModel = await _departmentService.GetDepartmentAsync(departmentId);

            if (departmentDetailsViewModel == null)
            {
                return(NotFound());
            }

            DepartmentDetailsViewModel = departmentDetailsViewModel;

            return(new NoContentResult());
        }
        public async Task <DepartmentDetailsViewModel> GetDepartmentAsync(int departmentId)
        {
            HttpResponseMessage response = await _httpClient.GetAsync($"department/get-department/{departmentId}");

            if (response.IsSuccessStatusCode)
            {
                string jsonString = await response.Content.ReadAsStringAsync();

                DepartmentDetailsViewModel departmentDetailsViewModel = JsonSerializer.Deserialize <DepartmentDetailsViewModel>(jsonString, JsonSerializerOptions);
                return(departmentDetailsViewModel);
            }

            throw new ApplicationException($"{response.ReasonPhrase}: The status code is: {(int)response.StatusCode}");
        }
Beispiel #13
0
        protected override async Task OnInitializedAsync()
        {
            DepartmentDetailsViewModel departmentDetailsViewModel = await _departmentService.GetByIdAsync(DepartmentId);

            if (departmentDetailsViewModel == null)
            {
                ErrorMessage = "Employee with provided id does not exists!";
            }

            UpdateDepartmentModel = new UpdateDepartmentViewModel()
            {
                DepartmentId   = departmentDetailsViewModel.DepartmentId,
                DepartmentName = departmentDetailsViewModel.DepartmentName,
                Description    = departmentDetailsViewModel.Description,
            };
        }
        public IActionResult DepartmentDetails(int id)
        {
            DepartmentDetailsViewModel model = new DepartmentDetailsViewModel
            {
                Departments = _context.Departments.Include(d => d.Doctors).
                              ToList(),
                //DoctorOpeningHourses=_context.DoctorsOpeningHours
                //.Include(d=>d.Doctor).FirstOrDefault(),
                //Doctor=_context.Doctors.Include(d=>d.DoctorOpeningHours).FirstOrDefault(),
                Department = _context.Departments.Include(d => d.Doctors)
                             .Where(d => d.Id == id)
                             .FirstOrDefault(),
                Clients = _context.Clients.ToList(),
            };

            return(View(model));
        }
        // Details Page
        public async Task <IActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            using (IDbConnection conn = Connection)
            {
                string sql = $@"
                     SELECT
                            d.Id,
                            d.[Name],
                            d.Budget,
                            e.Id,
                            e.FirstName,
                            e.LastName,
                            e.DepartmentId,
                            e.IsSuperVisor
                        FROM Department d
                        LEFT JOIN Employee e ON e.DepartmentId = d.Id 
                        WHERE d.Id = {id}                   
                    ";
                DepartmentDetailsViewModel model = new DepartmentDetailsViewModel();

                IEnumerable <DepartmentDetailsViewModel> queriedDepartment = await conn.QueryAsync <DepartmentDetailsViewModel, Employee, DepartmentDetailsViewModel>(
                    sql,
                    (dept, emp) =>
                {
                    if (model.Name == null)
                    {
                        model.Name   = dept.Name;
                        model.Budget = dept.Budget;
                    }

                    if (!model.AllEmployees.Contains(emp))
                    {
                        model.AllEmployees.Add(emp);
                    }

                    return(dept);
                });

                return(View(model));
            }
        }
        public ActionResult Details(int id)
        {
            //var department =  new MockDepartmentRepository().Get(id);
            var department = new DepartmentRepository(new SampleDbContext()).Get(id);



            DepartmentDetailsViewModel dvm = new DepartmentDetailsViewModel
            {
                Faculty   = department.Faculty.Name,
                FacultyId = department.Faculty.Id,
                Name      = department.Name
            };

            ViewBag.Dvm = dvm;


            return(View(dvm));
        }
        public async Task <IActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            DepartmentDetailsViewModel departmentDetailsViewModel = new DepartmentDetailsViewModel()
            {
                Department   = await _context.Departments.FirstOrDefaultAsync(d => d.ID == id),
                Workstations = _context.Workstations.Where(w => w.DepartmentID == id).Include(w => w.CurrentUser).Include(w => w.CurrentUnit)
            };

            if (departmentDetailsViewModel.Department == null)
            {
                return(NotFound());
            }

            return(View(departmentDetailsViewModel));
        }
Beispiel #18
0
        public IActionResult Details(int id)
        {
            DepartmentServiceModel department = this.departmentsService.GetById(id);

            if (department.Name == null)
            {
                return(this.BadRequest());
            }

            var model = new DepartmentDetailsViewModel
            {
                Id          = department.Id,
                Name        = department.Name,
                Email       = department.Email,
                Description = department.Description,
                // TODO: Add phones table
            };

            return(this.View(model));
        }
        // GET: Departments/Details/5
        public async Task <IActionResult> Details(long?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var department = await _context.Departments
                             .FirstOrDefaultAsync(m => m.DepartmentId == id);

            if (department == null)
            {
                return(NotFound());
            }
            DepartmentDetailsViewModel model = new DepartmentDetailsViewModel
            {
                Department      = department,
                DepartmentHead  = _context.ApplicationUsers.FirstOrDefault(u => u.Id == department.DepartmentHeadId),
                OwnedProjects   = _context.Projects.Where(p => p.OwnerDepartmentId == department.DepartmentId).ToList(),
                RelatedProjects = _context.Projects.Where(p => p.RelatedDepartments.Any(d => d.DepartmentId == department.DepartmentId)).ToList()
            };

            return(View(model));
        }
 protected override async Task OnInitializedAsync()
 {
     DepartmentDetailsModel = await _departmentService.GetByIdAsync(DepartmentId);
 }
Beispiel #21
0
        //todo: integration testing on Courses, Instructors, and Students
        //[InlineData("Courses")]
        //[InlineData("Instructors")]
        //[InlineData("Students")]
        public async Task CRUD(string controller)
        {
            var url = $"/{controller}/Create";

            using (var th = InitTestServer())
            {
                // get create form to retrieve antiforgery token
                var client   = th.CreateClient();
                var response = await client.GetAsync(url);

                Assert.Equal(HttpStatusCode.OK, response.StatusCode);

                // create entity
                var cookieVal    = response.GetAntiForgeryCookie(AntiForgeryCookieName).ToString();
                var formTokenVal = await response.GetAntiForgeryFormToken(AntiForgeryFormTokenName);

                client.DefaultRequestHeaders.Add("Cookie", cookieVal);

                var departmentToAdd = new DepartmentCreateViewModel {
                    Name = "Economics", Budget = 100000, StartDate = DateTime.Parse("2007-09-01"), InstructorID = 4
                };
                response = await client.PostFormDataAsync <DepartmentCreateViewModel>(url, departmentToAdd, formTokenVal);

                Assert.Equal(HttpStatusCode.Redirect, response.StatusCode);
                Assert.Contains("newid", response.Headers.Location.ToString());

                // verify entity was added
                var uri             = new Uri(client.BaseAddress, response.Headers.Location.ToString());
                var queryDictionary = QueryHelpers.ParseQuery(uri.Query);
                var newid           = queryDictionary["newid"];

                response = await client.GetAsync($"/{controller}/Details/{newid}");

                Assert.Equal(HttpStatusCode.OK, response.StatusCode);

                //edit new entity
                url      = $"/{controller}/Edit/{newid}";
                response = await client.GetAsync(url);

                formTokenVal = await response.GetAntiForgeryFormToken(AntiForgeryFormTokenName);

                var rowVersion = await response.GetRowVersion();

                var departmentToEdit = new DepartmentEditViewModel {
                    ID = int.Parse(newid), Name = "Economics 2", Budget = 999, StartDate = DateTime.UtcNow, RowVersion = rowVersion
                };
                response = await client.PostFormDataAsync <DepartmentEditViewModel>(url, departmentToEdit, formTokenVal);

                Assert.Equal(HttpStatusCode.Redirect, response.StatusCode);

                // delete new entity
                url      = $"/{controller}/delete/{newid}";
                response = await client.GetAsync(url);

                Assert.Equal(HttpStatusCode.OK, response.StatusCode);

                formTokenVal = await response.GetAntiForgeryFormToken(AntiForgeryFormTokenName);

                var departmentToDelete = new DepartmentDetailsViewModel {
                    ID = int.Parse(newid)
                };
                response = await client.PostFormDataAsync <DepartmentDetailsViewModel>(url, departmentToDelete, formTokenVal);

                Assert.Equal(HttpStatusCode.Redirect, response.StatusCode);
            }
        }
		void OnAdd()
		{
			ShortDepartment parentDepartment = null;
			var hasParentDepartment = SelectedDepartment != null;
			if (hasParentDepartment)
				parentDepartment = SelectedDepartment.Department;
			var departmentDetailsViewModel = new DepartmentDetailsViewModel();
			departmentDetailsViewModel.Initialize(_organisationUID, parentDepartment, Models);
			if (DialogService.ShowModalWindow(departmentDetailsViewModel))
			{
				var department = departmentDetailsViewModel.Model;
				var departmentViewModel = new DepartmentSelectionItemViewModel(department);
				if (hasParentDepartment)
				{
					SelectedDepartment.AddChild(departmentViewModel);
				}
				else
				{
					RootDepartments.Add(departmentViewModel);
					OnPropertyChanged(() => RootDepartments);
				}
				departmentViewModel.ExpandToThis();
				SelectedDepartment = departmentViewModel;
				ServiceFactory.Events.GetEvent<NewDepartmentEvent>().Publish(department);
			}
		}