Example #1
0
        // GET: Departments
        public ActionResult Index()
        {
            List <DepartmentsViewModel> model = new List <DepartmentsViewModel>();

            MobileWorkDataEntities entities = new MobileWorkDataEntities();

            try
            {
                List <Departments> departments = entities.Departments.OrderBy(Departments => Departments.DepartmentName).ToList();

                // muodostetaan näkymämalli tietokannan rivien pohjalta
                foreach (Departments department in departments)
                {
                    DepartmentsViewModel view = new DepartmentsViewModel();
                    view.Id_Department  = department.Id_Department;
                    view.DepartmentName = department.DepartmentName;

                    model.Add(view);
                }
            }
            finally
            {
                entities.Dispose();
            }

            return(View(model));
        }//Index
Example #2
0
        }//Index

        // GET: Departments/Details/5
        public ActionResult Details(int?id)
        {
            DepartmentsViewModel model = new DepartmentsViewModel();

            MobileWorkDataEntities entities = new MobileWorkDataEntities();

            try
            {
                Departments departmentdetail = entities.Departments.Find(id);

                if (departmentdetail == null)
                {
                    return(HttpNotFound());
                }

                // muodostetaan näkymämalli tietokannan rivien pohjalta
                DepartmentsViewModel view = new DepartmentsViewModel();
                view.Id_Department  = departmentdetail.Id_Department;
                view.DepartmentName = departmentdetail.DepartmentName;

                model = view;
            }

            finally
            {
                entities.Dispose();
            }

            return(View(model));
        }//details
        public IActionResult Details(int departmentId)
        {
            DepartmentsViewModel model = new DepartmentsViewModel();

            model.LoadDeatilsData(departmentId, _unitOfWork);
            return(View(model));
        }
        public IActionResult ConfirmDelete(int departmentId)
        {
            DepartmentsViewModel model = new DepartmentsViewModel();

            model.LoadConfirmDeleteData(departmentId, _unitOfWork);
            return(View(model));
        }
        public IActionResult List()
        {
            DepartmentsViewModel model = new DepartmentsViewModel();

            model.LoadListData(_unitOfWork);
            return(View(model));
        }
Example #6
0
        public async Task <IActionResult> Index(string InstId, bool FromPP)
        {
            //-----!!!! Это был тест отправки сообщений - пусть он тут побудет
            // EmailService es = new EmailService();
            // await es.SendEmailAsync("*****@*****.**", "SMTP_TEST", "YOLO");
            //-----!!!!!
            var inst = await(from i in DBContext.Institutions.Include(d => d.Departments).Include(m => m.Manager)
                             where i.Id.ToString() == InstId
                             select i).FirstOrDefaultAsync();
            var deps = await(from d in DBContext.Departments.Include(h => h.HeadTeacher)
                             where inst.Departments.Contains(d)
                             select d).ToListAsync();

            var departs = deps;
            var man     = inst.Manager;
            var name    = inst.Name;
            var mail    = inst.Manager.Email;
            //var manager
            var model = new DepartmentsViewModel()
            {
                InstitutionId   = InstId,
                InstitutionName = name,
                ManagerId       = man.Id,
                Departments     = deps,
                ManagerEmail    = mail,
                userGrants      = await checkService.getUserGrants(User)
            };

            model.FromPP = FromPP;
            return(View(model));
        }
Example #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());
		}
Example #8
0
        private DepartmentsViewModel GetDepartmentById(int id)
        {
            using (SqlConnection conn = Connection)
            {
                conn.Open();
                using (SqlCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = @"SELECT d.Id, d.[Name], d.Budget, COUNT(e.DepartmentId) as 'Employees'
                                        FROM Department d
                                        LEFT JOIN Employee e
                                        ON	e.DepartmentId = d.Id
                                        WHERE d.id = @id
                                        GROUP BY d.Name, d.Id, d.Budget ";
                    cmd.Parameters.Add(new SqlParameter("@id", id));
                    var reader = cmd.ExecuteReader();
                    DepartmentsViewModel department = null;

                    if (reader.Read())
                    {
                        department = new DepartmentsViewModel()
                        {
                            Id        = reader.GetInt32(reader.GetOrdinal("Id")),
                            Name      = reader.GetString(reader.GetOrdinal("Name")),
                            Budget    = reader.GetInt32(reader.GetOrdinal("Budget")),
                            Employees = reader.GetInt32(reader.GetOrdinal("Employees"))
                        };
                    }
                    reader.Close();
                    return(department);
                }
            }
        }
Example #9
0
        }//details

        // GET: Departments/Create
        public ActionResult Create()
        {
            MobileWorkDataEntities entities = new MobileWorkDataEntities();

            DepartmentsViewModel model = new DepartmentsViewModel();

            return(View(model));
        }//create
Example #10
0
        public ActionResult Edit(DepartmentsViewModel model)
        {
            Departments dep = new Departments();

            dep.DepartmentName = model.DepartmentName;

            db.SaveChanges();
            return(View("Index"));
        }//edit
Example #11
0
        public void AddDepartment(DepartmentsViewModel _department)
        {
            DepartmentsEntity department = new DepartmentsEntity();

            department.Id   = _department.Id;
            department.Name = _department.Name;

            new DepartmentsRepository().Insert(department);
        }
Example #12
0
        public async Task <IActionResult> Delete(int id, DepartmentsViewModel departmentsViewModel)
        {
            if (ModelState.IsValid)
            {
                await _departmentsViewModelService.DeleteDepartmentsAsync(departmentsViewModel.Id);

                return(RedirectToAction(nameof(Index)));
            }
            return(RedirectToAction(nameof(Index)));
        }
Example #13
0
        public DepartmentsViewModel ReadOneDepartment(int _id)
        {
            DepartmentsEntity    department    = new DepartmentsRepository().ReadOne(_id);
            DepartmentsViewModel department_vm = new DepartmentsViewModel();

            department_vm.Id   = department.Id;
            department_vm.Name = department.Name;

            return(department_vm);
        }
Example #14
0
        public async Task <ActionResult> Create(DepartmentsViewModel departments)
        {
            string userId = User.Identity.Name;

            if (ModelState.IsValid)
            {
                await _departmentsViewModelService.AddDepartmentsAsync(departments, userId);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(departments));
        }
Example #15
0
        public DepartmentsViewModel UpdateDepartment(DepartmentsViewModel _department)
        {
            DepartmentsEntity upd_department = new DepartmentsEntity()
            {
                Id   = _department.Id,
                Name = _department.Name
            };

            new DepartmentsRepository().Update(upd_department.Id, upd_department);

            return(this.ReadOneDepartment(_department.Id));
        }
Example #16
0
        public async Task <IActionResult> Create([FromBody] DepartmentsViewModel department)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            var map = mapper.Map <Department>(department);

            context.Departments.Add(map);
            await context.SaveChangesAsync();

            return(Ok());
        }
Example #17
0
        public async Task <IActionResult> Edit([FromBody] DepartmentsViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            var map = mapper.Map <Department>(model);

            context.Entry(map).State = EntityState.Modified;
            await context.SaveChangesAsync();

            return(Ok());
        }
Example #18
0
        public async Task <IActionResult> Index()
        {
            var user = await this.userManager.GetUserAsync(this.User);

            var companyId   = this.departmentService.GetCompanyIdByDepartmentId(user.DepartmentId);
            var departments = this.departmentService.GetAllDepartments(companyId);

            var model = new DepartmentsViewModel {
                Departments = departments
            };

            return(View(model));
        }
        public IActionResult Delete(int departmentId)
        {
            DepartmentsViewModel model = new DepartmentsViewModel();

            if (model.CountEmployeesOfThisDepartment(_unitOfWork.Departments.GetById(departmentId), _unitOfWork) == 0)
            {
                DeleteDepartment(_unitOfWork.Departments.GetById(departmentId));
                return(RedirectToAction(nameof(List)));
            }
            else
            {
                return(RedirectToAction(nameof(ConfirmDelete), new { departmentId = departmentId }));
            }
        }
Example #20
0
        public async Task <IActionResult> Edit(int id, DepartmentsViewModel departments)
        {
            string userId = User.Identity.Name;

            if (ModelState.IsValid)
            {
                await _departmentsViewModelService.UpdateDepartmentsAsync(departments, userId);

                return(RedirectToAction(nameof(Index)));
            }
            ViewBag.Locations = await _locationViewModelService.GetLocation();

            return(View(departments));
        }
Example #21
0
        public async Task UpdateDepartmentsAsync(DepartmentsViewModel departmentsVM, string userId)
        {
            _logger.LogInformation("UpdateDepartmentsAsync called.");
            var department = new Departments()
            {
                Id        = departmentsVM.Id,
                Name      = departmentsVM.Name,
                LocatonId = departmentsVM.LocatonId,
                ManagerId = departmentsVM.ManagerId,
                Image     = departmentsVM.Image,
                UpdatedAt = DateTime.Now,
                UpdatedBy = userId
            };

            await _asyncRepository.UpdateAsync(department);
        }
Example #22
0
        public async Task <DepartmentsViewModel> GetDepartmentsAsync(int id)
        {
            _logger.LogInformation("GetDepartmentsAsync called.");
            var departmentget = await _asyncRepository.GetByIdAsync(id);

            var department = new DepartmentsViewModel()
            {
                Id        = departmentget.Id,
                Name      = departmentget.Name,
                LocatonId = departmentget.LocatonId,
                ManagerId = departmentget.ManagerId,
                Image     = departmentget.Image,
            };

            return(department);
        }
Example #23
0
        // GET: Departments/Details/5
        public ActionResult Details(int id)
        {
            using (SqlConnection conn = Connection)
            {
                conn.Open();
                using (SqlCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = @"SELECT d.Id, d.[Name], d.Budget, e.DepartmentId, e.FirstName, e.LastName, e.Id As EmployeeId
                                        FROM Department d
                                        LEFT JOIN Employee e
                                        ON	e.DepartmentId = d.Id
                                        WHERE d.Id = @id";
                    cmd.Parameters.Add(new SqlParameter("@id", id));
                    var reader = cmd.ExecuteReader();
                    DepartmentsViewModel department = null;


                    while (reader.Read())
                    {
                        if (department == null)
                        {
                            department = new DepartmentsViewModel
                            {
                                Id            = reader.GetInt32(reader.GetOrdinal("Id")),
                                Name          = reader.GetString(reader.GetOrdinal("Name")),
                                Budget        = reader.GetInt32(reader.GetOrdinal("Budget")),
                                DeptEmployees = new List <Employee>()
                            };
                        }
                        if (!reader.IsDBNull(reader.GetOrdinal("EmployeeId")))
                        {
                            department.DeptEmployees.Add(new Employee()
                            {
                                Id           = reader.GetInt32(reader.GetOrdinal("EmployeeId")),
                                DepartmentId = reader.GetInt32(reader.GetOrdinal("DepartmentId")),
                                FirstName    = reader.GetString(reader.GetOrdinal("FirstName")),
                                LastName     = reader.GetString(reader.GetOrdinal("LastName"))
                            });
                        }
                    }
                    reader.Close();
                    return(View(department));
                }
            }
        }
Example #24
0
        public JsonResult GetOrganisations(DepartmentFilter departmentFilter)
        {
            var departmentViewModel = new DepartmentsViewModel();
            departmentViewModel.Initialize(new DepartmentFilter
            {
                OrganisationUIDs = departmentFilter.OrganisationUIDs,
                LogicalDeletationType = departmentFilter.LogicalDeletationType
            });
            dynamic result = new
            {
                page = 1,
                total = 100,
                records = 100,
                rows = departmentViewModel.Organisations,
            };

            return Json(result, JsonRequestBehavior.AllowGet);
        }
        public IActionResult ConfirmDelete(DepartmentsViewModel model)
        {
            model.AssignDepartment = _unitOfWork.Departments.GetById(model.AssignDepartment.Id);
            model.EmployeeList     = _unitOfWork.Employees.GetEmployeeByDepartmentId(model.Department.Id);

            foreach (var emp in model.EmployeeList)
            {
                emp.DepartmentId = model.AssignDepartment.Id;
                emp.Department   = model.AssignDepartment;

                _unitOfWork.Employees.Update(emp);
                _unitOfWork.Save();
            }

            DeleteDepartment(_unitOfWork.Departments.GetById(model.Department.Id));

            return(RedirectToAction(nameof(List)));
        }
Example #26
0
        }//edit

        // GET: Departments/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Departments departmentdetail = db.Departments.Find(id);

            if (departmentdetail == null)
            {
                return(HttpNotFound());
            }
            DepartmentsViewModel view = new DepartmentsViewModel();

            view.Id_Department  = departmentdetail.Id_Department;
            view.DepartmentName = departmentdetail.DepartmentName;

            return(View(view));
        }
Example #27
0
		public HRViewModel(SKDTabItems skdTabItems)
		{
			SKDTabItems = skdTabItems;
			EditFilterCommand = new RelayCommand(OnEditFilter, CanEditFilter);
			ChangeIsDeletedCommand = new RelayCommand(OnChangeIsDeleted, CanChangeIsDeleted);
			EmployeesViewModel = new EmployeesViewModel();
			DepartmentsViewModel = new DepartmentsViewModel();
			PositionsViewModel = new PositionsViewModel();
			AdditionalColumnTypesViewModel = new AdditionalColumnTypesViewModel();
			CardsViewModel = new CardsViewModel();
			AccessTemplatesViewModel = new AccessTemplatesViewModel();
			PassCardTemplatesViewModel = new PassCardTemplatesViewModel();
			OrganisationsViewModel = new OrganisationsViewModel();
			DepartmentFilter = new DepartmentFilter();
			PositionFilter = new PositionFilter();
			CardFilter = new CardFilter();
			if (CanSelectEmployees) 
				IsEmployeesSelected = true;
			else if (CanSelectDepartments) 
				IsDepartmentsSelected = true;
			else if (CanSelectPositions) 
				IsPositionsSelected = true;
			else if (CanSelectAdditionalColumns) 
				IsAdditionalColumnTypesSelected = true;
			else if (CanSelectCards) 
				IsCardsSelected = true;
			else if (CanSelectAccessTemplates) 
				IsAccessTemplatesSelected = true;
			else if (CanSelectPassCardTemplates) 
				IsPassCardTemplatesSelected = true;
			else if (CanSelectOrganisations) 
				IsOrganisationsSelected = true;
			PersonTypes = new ObservableCollection<PersonType>();
			if (ClientManager.CurrentUser.HasPermission(PermissionType.Oper_SKD_Employees_View))
				PersonTypes.Add(PersonType.Employee);
			if (ClientManager.CurrentUser.HasPermission(PermissionType.Oper_SKD_Guests_View))
				PersonTypes.Add(PersonType.Guest);
			_selectedPersonType = PersonTypes.FirstOrDefault();
			var user = ClientManager.CurrentUser;
			Filter = new HRFilter() { User = user };
			Filter.EmployeeFilter.User = user;
		}
Example #28
0
        public ActionResult Create(DepartmentsViewModel model)
        {
            MobileWorkDataEntities entities = new MobileWorkDataEntities();


            Departments dep = new Departments();

            dep.DepartmentName = model.DepartmentName;

            db.Departments.Add(dep);

            try
            {
                db.SaveChanges();
            }

            catch (Exception ex)
            {
            }

            return(RedirectToAction("Index"));
        }//create
Example #29
0
        }//create

        // GET: Departments/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Departments departmentdetail = db.Departments.Find(id);

            if (departmentdetail == null)
            {
                return(HttpNotFound());
            }

            DepartmentsViewModel view = new DepartmentsViewModel();

            view.Id_Department  = departmentdetail.Id_Department;
            view.DepartmentName = departmentdetail.DepartmentName;


            //ViewBag.Id_Employee = new SelectList(db.Employees, "Id_Employee", "FirstName", departments.Id_Employee);

            return(View(view));
        }
Example #30
0
        // GET: Departments/Create
        public ActionResult Create()
        {
            var viewModel = new DepartmentsViewModel();

            return(View(viewModel));
        }
Example #31
0
        public JsonResult GetDepartmentsFilter(bool isWithDeleted)
        {
            var filter = new DepartmentFilter { User = ClientManager.CurrentUser };
            if (isWithDeleted)
            {
                filter.LogicalDeletationType = LogicalDeletationType.All;
            }

            var departmentViewModel = new DepartmentsViewModel();
            departmentViewModel.Initialize(filter);

            dynamic result = new
            {
                page = 1,
                total = 100,
                records = 100,
                rows = departmentViewModel.Organisations,
            };

            return Json(result, JsonRequestBehavior.AllowGet);
        }
 public DepartmentsPage()
 {
     InitializeComponent();
     BindingContext = _viewModel = new DepartmentsViewModel();
 }
Example #33
0
		public void DeleteChild()
		{
			var organisation = new Organisation();
			var department = new ShortDepartment { UID = Guid.NewGuid(), Name = "Name1", OrganisationUID = organisation.UID };
			var childDepartment = new ShortDepartment 
				{ 
					UID = Guid.NewGuid(),
					Name = "Name2", 
					OrganisationUID = organisation.UID, 
					ParentDepartmentUID = department.UID, 
					IsDeleted = true 
				};
			department.ChildDepartments.Add(new TinyDepartment { Name = childDepartment.Name, UID = childDepartment.UID });
			var mock = new Mock<ISafeRubezhService>();
			mock.Setup(x => x.GetOrganisations(It.IsAny<OrganisationFilter>())).Returns(() =>
			{
				return new OperationResult<List<Organisation>>(new List<Organisation> { organisation });
			});
			mock.Setup(x => x.GetDepartmentList(It.IsAny<DepartmentFilter>())).Returns(() =>
			{
				return new OperationResult<List<ShortDepartment>>(new List<ShortDepartment> { department, childDepartment });
			});
			mock.Setup(x => x.GetEmployeeList(It.IsAny<EmployeeFilter>())).Returns(() =>
			{
				return new OperationResult<List<ShortEmployee>>();
			});
			mock.Setup(x => x.RestoreDepartment(It.IsAny<ShortDepartment>())).Returns<ShortDepartment>(shortDeaprtment =>
			{
				if (shortDeaprtment.UID == department.UID)
					department.IsDeleted = false;
				if (shortDeaprtment.UID == childDepartment.UID)
					childDepartment.IsDeleted = false;
				return new OperationResult<bool>(true);
			});
			mock.Setup(x => x.GetParentEmployeeUIDs(It.IsAny<Guid>())).Returns<Guid>(uid =>
			{
				var result = new List<Guid>();
				if(uid == childDepartment.UID)
					result.Add(department.UID);
				return new OperationResult<List<Guid>>(result);
			});
			ClientManager.RubezhService = mock.Object;
			(ServiceFactory.MessageBoxService as MockMessageBoxService).ShowConfirmationResult = true;
			var departmentsViewModel = new DepartmentsViewModel();
			departmentsViewModel.Initialize(new DepartmentFilter());
			departmentsViewModel.SelectedItem = departmentsViewModel.Organisations.SelectMany(x  => x.GetAllChildren()).FirstOrDefault(x => x.UID == childDepartment.UID);
			if (departmentsViewModel.RestoreCommand.CanExecute(null))
				departmentsViewModel.RestoreCommand.ForceExecute();
			else
				Assert.IsTrue(false);
			departmentsViewModel.Initialize(new DepartmentFilter());
			var department2 = departmentsViewModel.Models.FirstOrDefault(x => x.UID == department.UID);
			var childDepartment2 = departmentsViewModel.Models.FirstOrDefault(x => x.UID == childDepartment.UID);
			Assert.IsFalse(department2.IsDeleted || childDepartment2.IsDeleted);
		}
Example #34
0
 public IActionResult Edit(DepartmentsViewModel department)
 {
     _departmentsManager.UpdateDepartment(department);
     return(RedirectToAction("Index"));
 }
Example #35
0
        public ViewResult Edit(int?_id)
        {
            DepartmentsViewModel department = _departmentsManager.ReadOneDepartment((int)_id);

            return(View(department));
        }