Esempio n. 1
0
        public async Task <IActionResult> OnPostAsync(string id)
        {
            try
            {
                if (_getAccountDataService.IsSystemAdmin())
                {
                    DocumentType type = await db.DocumentType.FirstAsync(r => r.Id.ToString() == id);

                    if (type != null)
                    {
                        db.DocumentType.Remove(type);
                        await db.SaveChangesAsync();
                    }
                    return(RedirectToPage("/Managing/DocumentTypes/Index"));
                }
                else
                {
                    return(NotFound());
                }
            }
            catch (Exception e)
            {
                _logger.LogError(e, "Error while deleting document type");
                return(NotFound());
            }
        }
Esempio n. 2
0
        public async Task <IActionResult> OnPostDeleteAsync(Guid titleId, Guid documentTypeId)
        {
            try
            {
                if (_getAccountDataService.IsSystemAdmin())
                {
                    DocumentTitle deletingTitle = await db.DocumentTitle
                                                  .Where(dt => dt.DocumentTypeId.Equals(documentTypeId))
                                                  .FirstOrDefaultAsync(r => r.Id.Equals(titleId));

                    if (deletingTitle != null)
                    {
                        db.DocumentTitle.Remove(deletingTitle);
                        await db.SaveChangesAsync();
                    }
                    return(RedirectToPage("Index", new { documentTypeId }));
                }
                else
                {
                    return(NotFound());
                }
            }
            catch (Exception e)
            {
                _logger.LogError(e, "Error while deleting document title");
                return(NotFound());
            }
        }
Esempio n. 3
0
        public async Task <IActionResult> OnPostAsync(string type)
        {
            try
            {
                if (_getAccountDataService.IsSystemAdmin())
                {
                    await db.DocumentType.AddAsync(new DocumentType(type));

                    int result = await db.SaveChangesAsync();

                    if (result > 0)
                    {
                        return(RedirectToPage("Index"));
                    }

                    return(Page());
                }
                else
                {
                    return(NotFound());
                }
            }
            catch (Exception e)
            {
                _logger.LogError(e, "Error while adding new Document type");
                return(NotFound());
            }
        }
Esempio n. 4
0
        public async Task <IActionResult> OnPostAsync(string name)
        {
            try
            {
                if (_getAccountDataService.IsSystemAdmin())
                {
                    if (!string.IsNullOrEmpty(name))
                    {
                        await db.Role.AddAsync(new Role(name));

                        int result = await db.SaveChangesAsync();

                        if (result > 0)
                        {
                            return(RedirectToPage("Index"));
                        }
                    }
                    return(Page());
                }
                else
                {
                    return(NotFound());
                }
            }
            catch (Exception e)
            {
                _logger.LogError(e, "Error while adding new Department Role");
                return(NotFound());
            }
        }
Esempio n. 5
0
        public async Task <int> SaveDocumentPathAsync(Guid departmentsDocumentId, string FileName, string path, Guid userId)
        {
            await db.DepartmentsDocumentsVersion
            .AddAsync(new DepartmentsDocumentsVersion(departmentsDocumentId, FileName, path, DateTime.UtcNow, userId));

            return(await db.SaveChangesAsync());
        }
Esempio n. 6
0
        public async Task <IActionResult> OnPostAsync(string id)
        {
            try
            {
                if (_getAccountDataService.IsSystemAdmin())
                {
                    ReportingYear year = await db.ReportingYear.FirstAsync(r => r.Id.ToString() == id);

                    if (year != null)
                    {
                        db.ReportingYear.Remove(year);
                        await db.SaveChangesAsync();
                    }
                    return(RedirectToPage("/Managing/ReportingYears/Index"));
                }
                else
                {
                    return(NotFound());
                }
            }
            catch (Exception e)
            {
                _logger.LogError(e, "Error while deleting year");
                return(NotFound());
            }
        }
Esempio n. 7
0
        public async Task <IActionResult> OnPostAsync(string name)
        {
            try
            {
                if (_getAccountDataService.IsSystemAdmin())
                {
                    if (!string.IsNullOrEmpty(name))
                    {
                        Department newDepartment = new Department();
                        newDepartment.Name = name;

                        await db.Department.AddAsync(newDepartment);

                        await db.SaveChangesAsync();

                        return(RedirectToPage("DepartmentsList"));
                    }
                    return(Page());
                }
                else
                {
                    return(NotFound());
                }
            }
            catch (Exception e)
            {
                _logger.LogError(e, "Error while creating new department");
                return(NotFound());
            }
        }
Esempio n. 8
0
        public async Task <IActionResult> OnPostAsync(string id)
        {
            try
            {
                if (_getAccountDataService.IsSystemAdmin())
                {
                    Role role = await db.Role.FirstAsync(r => r.Id.ToString() == id);

                    if (role != null)
                    {
                        db.Role.Remove(role);
                        await db.SaveChangesAsync();
                    }
                    return(RedirectToPage("/Managing/UserRoleDepartmentManagement/Roles/Index"));
                }
                else
                {
                    return(NotFound());
                }
            }
            catch (Exception e)
            {
                _logger.LogError(e, "Error while deleting department Role");
                return(NotFound());
            }
        }
Esempio n. 9
0
        public async Task <IActionResult> OnPostDeleteAsync(string id)
        {
            try
            {
                if (_getAccountDataService.IsSystemAdmin())
                {
                    if (id.Equals(null))
                    {
                        return(Page());
                    }

                    Department Department = await db.Department.FirstOrDefaultAsync <Department>(d => d.Id.ToString() == id);

                    if (Department != null)
                    {
                        db.Department.Remove(Department);
                        await db.SaveChangesAsync();
                    }
                    return(RedirectToPage("/Managing/UserRoleDepartmentManagement/Departments/DepartmentsList"));
                }
                else
                {
                    return(NotFound());
                }
            }
            catch (Exception e)
            {
                _logger.LogError(e, "Error while deleting department");
                return(NotFound());
            }
        }
Esempio n. 10
0
        public async Task <IActionResult> OnPostAsync(Guid titleId, string titleName, string titleDescription)
        {
            try
            {
                if (_getAccountDataService.IsSystemAdmin())
                {
                    selectedDocumentTitle = await db.DocumentTitle
                                            .Include(dt => dt.DocumentType)
                                            .FirstOrDefaultAsync(dt => dt.Id == titleId);

                    if (selectedDocumentTitle != null)
                    {
                        if (selectedDocumentTitle.Description != titleDescription || selectedDocumentTitle.Name != titleName)
                        {
                            if (selectedDocumentTitle.Name != titleName)
                            {
                                selectedDocumentTitle.Name = titleName;
                            }

                            if (selectedDocumentTitle.Description != titleDescription)
                            {
                                selectedDocumentTitle.Description = titleDescription;
                            }

                            if (await TryUpdateModelAsync <DocumentTitle>(selectedDocumentTitle))
                            {
                                if (await db.SaveChangesAsync() > 0)
                                {
                                    return(RedirectToPage("Index", new { documentTypeId = selectedDocumentTitle.DocumentType.Id }));
                                }
                            }
                        }
                        else
                        {
                            return(RedirectToPage("Index", new { documentTypeId = selectedDocumentTitle.DocumentType.Id }));
                        }

                        _logger.LogError("Error while saving changed on page of Editing document title.\nFailed to save changes");
                        return(NotFound());
                    }
                    else
                    {
                        _logger.LogError("Error while saving changed on page of Editing document title.\nFailed to load document title");
                        return(NotFound());
                    }
                }
                else
                {
                    return(NotFound());
                }
            }
            catch (Exception e)
            {
                _logger.LogError(e, "Error while saving changed on page of Editing document title");
                return(NotFound());
            }
        }
Esempio n. 11
0
        private async Task <int> AddDocumentStatusAsync(Guid newStatusId, string comment, Guid departmentDocumentId, Guid userId)
        {
            var newStatus = new DocumentStatusHistory(newStatusId, comment, departmentDocumentId, DateTime.Now, userId);
            var UpdatedDepartamentDocument = (await db.DepartmentsDocument.FirstOrDefaultAsync(dd => dd.Id == departmentDocumentId));

            UpdatedDepartamentDocument.DocumentStatusHistories.Add(newStatus);
            UpdatedDepartamentDocument.LastSetDocumentStatusId = newStatusId;
            db.DepartmentsDocument.Update(UpdatedDepartamentDocument);


            return(await db.SaveChangesAsync());
        }
Esempio n. 12
0
        private async Task InitializeReportingYearsList()
        {
            if (db.ReportingYear.FirstOrDefault(y => y.Number == DateTime.Now.Year) == null)
            {
                await db.ReportingYear.AddAsync(new ReportingYear(DateTime.Now.Year));

                await db.SaveChangesAsync();
            }
        }
Esempio n. 13
0
        public async Task <IActionResult> OnPostAsync(int number, List <Guid> titles, List <Guid> types, string addAll)
        {
            try
            {
                if (_getAccountDataService.IsSystemAdmin())
                {
                    var newReportingYear = new ReportingYear(number);
                    await db.ReportingYear.AddAsync(newReportingYear);

                    int result = await db.SaveChangesAsync();

                    if (result > 0)
                    {
                        await AddDocumentTitlesToNewReportingYearAsync(newReportingYear.Id, titles, types, addAll);

                        result = await db.SaveChangesAsync();

                        if (result > 0)
                        {
                            return(RedirectToPage("Index"));
                        }
                    }

                    return(Page());
                }
                else
                {
                    return(NotFound());
                }
            }
            catch (Exception e)
            {
                _logger.LogError(e, "Error while adding new ReportingYear");
                return(NotFound());
            }
        }
Esempio n. 14
0
        public async Task <DepartmentsDocument> GetDepartmentsDocument(Guid departmentId, Guid reportingYearDocumentTitleId)
        {
            DepartmentsDocument departmentsDocument;

            if (await db.DepartmentsDocument.FirstOrDefaultAsync(dd => dd.DepartmentId == departmentId &&
                                                                 dd.ReportingYearDocumentTitleId == reportingYearDocumentTitleId) != null)
            {
                departmentsDocument = await db.DepartmentsDocument
                                      .FirstOrDefaultAsync(dd => dd.DepartmentId == departmentId &&
                                                           dd.ReportingYearDocumentTitleId == reportingYearDocumentTitleId);
            }
            else
            {
                departmentsDocument = new DepartmentsDocument(departmentId, reportingYearDocumentTitleId);

                await db.DepartmentsDocument.AddAsync(departmentsDocument);

                await db.SaveChangesAsync();
            }
            return(departmentsDocument);
        }
Esempio n. 15
0
        public async Task <IActionResult> OnPostUpdateRolesAsync(string userId, string departmentId, List <string> roles)
        {
            try
            {
                if (await _getAccountDataService.UserIsAdminOnAnyDepartment() || _getAccountDataService.IsSystemAdmin())
                {
                    if (ModelState.IsValid)
                    {
                        // получаем пользователя
                        User user = await _userManager.FindByIdAsync(userId);

                        if (user != null)
                        {
                            // получем список ролей пользователя
                            var UserDepartmentRoles = await db.UserRoleDepartment
                                                      .Where(urd => urd.UserId.Equals(Guid.Parse(userId)) && urd.DepartmentId.ToString() == departmentId)
                                                      .Select(urd => urd.Role.Id.ToString().ToLower())
                                                      .ToListAsync();

                            // получаем список ролей, которые были добавлены
                            var addedRoles = roles.Except(UserDepartmentRoles);

                            var allRoles = db.Role
                                           .Select(r => r.Id.ToString().ToLower())
                                           .ToList();

                            // получаем роли, которые были удалены
                            var removedRoles = UserDepartmentRoles.Except(roles);

                            foreach (var role in addedRoles)
                            {
                                if (role != null)
                                {
                                    db.UserRoleDepartment.Add(new UserDepartmentRole()
                                    {
                                        UserId       = Guid.Parse(userId),
                                        DepartmentId = Guid.Parse(departmentId),
                                        RoleId       = Guid.Parse(role)
                                    });
                                }
                            }

                            foreach (var role in removedRoles)
                            {
                                if (role != null)
                                {
                                    UserDepartmentRole removingRecord = await db.UserRoleDepartment
                                                                        .FirstOrDefaultAsync(urd => urd.RoleId.Equals(Guid.Parse(role)) &&
                                                                                             urd.UserId.Equals(Guid.Parse(userId)) &&
                                                                                             urd.DepartmentId.Equals(Guid.Parse(departmentId)));

                                    db.UserRoleDepartment.Remove(removingRecord);
                                }
                            }

                            await db.SaveChangesAsync();

                            return(RedirectToPage("UserDepartmentList"));
                        }
                        else
                        {
                            return(NotFound());
                        }
                    }
                    else
                    {
                        return(Page());
                    }
                }
                else
                {
                    return(NotFound());
                }
            }
            catch (Exception e)
            {
                _logger.LogError(e, "Error while saving Department Data for this User");
                return(NotFound());
            }
        }
Esempio n. 16
0
        private async Task <int> CreateNewDocumentTitle(string name, Guid documentTypeId, string description)
        {
            await db.DocumentTitle.AddAsync(new DocumentTitle(name, documentTypeId, description));

            return(await db.SaveChangesAsync());
        }