Beispiel #1
0
        public async Task <IActionResult> UpdateDepartment(int Id)
        {
            try
            {
                var result = await _departmentsRepository.GetDepartmentById(Id);

                return(Ok(result));
            }
            catch (Exception x)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
Beispiel #2
0
        public async Task <ResponseDto <Department> > GetDepartmentById(int id)
        {
            var departmentFromDb = await _departmentsRepository.GetDepartmentById(id);

            ResponseDto <Department> response = DepartmentsValidator.ValidateGetDepartmentById(departmentFromDb);

            if (response.HasErrors)
            {
                return(response);
            }

            response.Value = departmentFromDb;
            return(response);
        }
Beispiel #3
0
        public async Task <ResponseDto <List <GetDocumentTypeDto> > > GetDocumentTypes(int departmentId)
        {
            var departmentFromDb = await _departmentsRepository.GetDepartmentById(departmentId);

            ResponseDto <List <GetDocumentTypeDto> > response = DocumentTypesValidator.ValidateGetDocumentTypes(departmentFromDb);

            if (response.HasErrors)
            {
                return(response);
            }
            var DocumentTypesFromDb = await _documentTypesRepository.GetDocumentTypes(departmentFromDb);

            response.Value = Mapper.Map <List <GetDocumentTypeDto> >(DocumentTypesFromDb);
            return(response);
        }
Beispiel #4
0
        public async Task <ResponseDto <int> > AddCase(ClaimsPrincipal user, AddCaseDto caseToAdd)
        {
            var userFromDb = await _usersRepository.GetUserByLogin(user.Identity.Name);

            var departmentFromDb = await _departmentsRepository.GetDepartmentById(caseToAdd.DepartmentId);

            var response = CasesValidator.ValidateAddCase(caseToAdd, departmentFromDb, userFromDb);

            if (response.HasErrors)
            {
                return(response);
            }

            var caseToDb = Mapper.Map <Case>(caseToAdd);

            caseToDb.Status     = "Sent";
            caseToDb.IsDeleted  = false;
            caseToDb.Department = departmentFromDb;
            caseToDb.SendDate   = DateTime.Now;
            caseToDb.Sender     = userFromDb;
            response.Value      = await _casesRepository.AddCase(caseToDb);

            return(response);
        }