Ejemplo n.º 1
0
        public async Task <ActionResponse <PrinterDto> > GetById(int id)
        {
            try
            {
                var query = unitOfWork.GetGenericRepository <Printer>()
                            .ReadAllActiveAsQueryable()
                            .Where(e => e.Id == id);

                var entity = mapper.ProjectTo <PrinterDto>(query).FirstOrDefault();

                return(await ActionResponse <PrinterDto> .ReturnSuccess(entity));
            }
            catch (Exception)
            {
                return(await ActionResponse <PrinterDto> .ReturnError("Greška prilikom dohvata printera."));
            }
        }
Ejemplo n.º 2
0
        public async Task <ActionResponse <List <IssuedPrintDto> > > GetForStudentAndProgram(IssuedPrintDto entityDto)
        {
            try
            {
                var query = unitOfWork.GetGenericRepository <IssuedPrint>()
                            .ReadAllActiveAsQueryable()
                            .Where(e => e.StudentId == entityDto.StudentId && e.EducationProgramId == entityDto.EducationProgramId);

                var entity = mapper.ProjectTo <IssuedPrintDto>(query).ToList();

                return(await ActionResponse <List <IssuedPrintDto> > .ReturnSuccess(entity));
            }
            catch (Exception)
            {
                return(await ActionResponse <List <IssuedPrintDto> > .ReturnError("Greška prilikom dohvata izdanih duplikata za polaznika."));
            }
        }
Ejemplo n.º 3
0
        public async Task <ActionResponse <PagedResult <StudentRegisterEntryDto> > > GetAllEntriesByBookIdPaged(BasePagedRequest pagedRequest)
        {
            try
            {
                var entityDtos = (await GetAllEntries()).GetData();

                var pagedResult = await entityDtos
                                  .Where(e => e.StudentRegisterId == pagedRequest.AdditionalParams.Id)
                                  .AsQueryable().GetPaged(pagedRequest);

                return(await ActionResponse <PagedResult <StudentRegisterEntryDto> > .ReturnSuccess(pagedResult));
            }
            catch (Exception)
            {
                return(await ActionResponse <PagedResult <StudentRegisterEntryDto> > .ReturnError("Greška prilikom dohvata straničnih podataka zapisa matične knjige."));
            }
        }
Ejemplo n.º 4
0
        public async Task <ActionResponse <ClassTypeDto> > Update(ClassTypeDto entityDto)
        {
            try
            {
                var entityToUpdate = mapper.Map <ClassTypeDto, ClassType>(entityDto);
                unitOfWork.GetGenericRepository <ClassType>().Update(entityToUpdate);
                unitOfWork.Save();
                await cacheService.RefreshCache <List <ClassTypeDto> >();

                return(await ActionResponse <ClassTypeDto>
                       .ReturnSuccess(mapper.Map <ClassType, ClassTypeDto>(entityToUpdate)));
            }
            catch (Exception)
            {
                return(await ActionResponse <ClassTypeDto> .ReturnError("Greška prilikom ažuriranja vrste nastave."));
            }
        }
Ejemplo n.º 5
0
        public async Task <ActionResponse <DiaryStudentGroupDto> > InsertDiaryStudentGroup(DiaryStudentGroupDto entityDto)
        {
            try
            {
                var entityToAdd = mapper.Map <DiaryStudentGroupDto, DiaryStudentGroup>(entityDto);
                unitOfWork.GetGenericRepository <DiaryStudentGroup>().Add(entityToAdd);
                unitOfWork.Save();
                mapper.Map(entityToAdd, entityDto);

                return(await ActionResponse <DiaryStudentGroupDto>
                       .ReturnSuccess(mapper.Map(entityToAdd, entityDto)));
            }
            catch (Exception)
            {
                return(await ActionResponse <DiaryStudentGroupDto> .ReturnError("Greška prilikom unošenja grupe studenata za dnevnik rada."));
            }
        }
Ejemplo n.º 6
0
        public async Task <ActionResponse <PlanDaySubjectDto> > ModifyPlanDaySubjectsThemes(PlanDaySubjectDto entityDto)
        {
            var entity = unitOfWork.GetGenericRepository <PlanDaySubject>()
                         .FindBy(p => p.Id == entityDto.Id, includeProperties: "PlanDaySubjectThemes.Theme");

            var currentThemes = mapper.Map <List <PlanDaySubjectTheme>, List <PlanDaySubjectThemeDto> >(entity.PlanDaySubjectThemes.ToList());

            var themesToRemove = currentThemes.Where(cd => !entityDto.PlanDaySubjectThemes
                                                     .Select(pdst => pdst.ThemeId.Value)
                                                     .Contains(cd.ThemeId.Value))
                                 .ToList();

            var themesToAdd = entityDto.PlanDaySubjectThemes
                              .Where(nt => !currentThemes.Select(cd => cd.ThemeId.Value).Contains(nt.ThemeId.Value))
                              .Select(pds => new PlanDaySubjectThemeDto
            {
                ThemeId          = pds.ThemeId.Value,
                PlanDaySubjectId = entity.Id,
                HoursNumber      = pds.HoursNumber,
                ClassTypes       = pds.ClassTypes,
                PerfomingType    = pds.PerfomingType,
            }).ToList();

            var themesToModify = entityDto.PlanDaySubjectThemes.Where(cd => currentThemes
                                                                      .Select(pdst => pdst.ThemeId.Value)
                                                                      .Contains(cd.ThemeId.Value)).ToList();

            if ((await AddThemesToPlanDaySubject(themesToAdd))
                .IsNotSuccess(out ActionResponse <List <PlanDaySubjectThemeDto> > actionResponse, out themesToAdd))
            {
                return(await ActionResponse <PlanDaySubjectDto> .ReturnError("Neuspješno ažuriranje predmeta u danu plana."));
            }

            if ((await ModifyThemesInPlanDaySubject(themesToModify)).IsNotSuccess(out actionResponse, out themesToModify))
            {
                return(await ActionResponse <PlanDaySubjectDto> .ReturnError("Neuspješno ažuriranje predmeta u danu plana."));
            }

            if ((await RemoveThemesFromPlanDaySubject(themesToRemove))
                .IsNotSuccess(out actionResponse))
            {
                return(await ActionResponse <PlanDaySubjectDto> .ReturnError(actionResponse.Message));
            }

            return(await ActionResponse <PlanDaySubjectDto> .ReturnSuccess(mapper.Map(entity, entityDto), "Uspješno izmijenjeni dani plana."));
        }
Ejemplo n.º 7
0
        public async Task <ActionResponse <List <StudentRegisterEntryDto> > > GetAllEntriesForCache()
        {
            try
            {
                if ((await GetAllEntries())
                    .IsNotSuccess(out ActionResponse <List <StudentRegisterEntryDto> > response, out List <StudentRegisterEntryDto> entityDtos))
                {
                    return(response);
                }

                return(await ActionResponse <List <StudentRegisterEntryDto> > .ReturnSuccess(entityDtos));
            }
            catch (Exception)
            {
                return(await ActionResponse <List <StudentRegisterEntryDto> > .ReturnError("Greška prilikom dohvata svih zapisa matičnih knjiga."));
            }
        }
Ejemplo n.º 8
0
        public async Task <ActionResponse <UserViewModel> > Create(UserViewModel request)
        {
            try
            {
                using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
                {
                    request.DateCreated = DateTime.UtcNow;
                    var user   = mapper.Map <UserViewModel, User>(request);
                    var result = await userManager.CreateAsync(user, request.Password);

                    if (!result.Succeeded)
                    {
                        return(await ActionResponse <UserViewModel> .ReturnError("Failed to create new user."));
                    }

                    request.Id = user.Id;

                    if ((await AddToDefaultRole(request)).IsNotSuccess(out ActionResponse <UserViewModel> actionResponse, out request))
                    {
                        return(await ActionResponse <UserViewModel> .ReturnError("Failed to edit user's roles.", request));
                    }

                    if ((await ModifyUserRoles(request)).IsNotSuccess(out actionResponse, out request))
                    {
                        return(await ActionResponse <UserViewModel> .ReturnError("Failed to edit user's roles."));
                    }

                    if ((await userDetailsService.CreateUserDetails(request)).IsNotSuccess(out actionResponse, out request))
                    {
                        return(actionResponse);
                    }
                    scope.Complete();
                }

                return(await ActionResponse <UserViewModel> .ReturnSuccess(request));
            }
            catch (Exception)
            {
                return(await ActionResponse <UserViewModel> .ReturnError("Dogodila se greška, molimo kontaktirajte svog administratora."));
            }
            finally
            {
                await cacheService.RefreshCache <List <UserDto> >();
            }
        }
        public async Task <ActionResponse <EducationProgramDto> > ModifyClassTypes(EducationProgramDto entityDto)
        {
            try
            {
                var entity = unitOfWork.GetGenericRepository <EducationProgram>()
                             .FindBy(e => e.Id == entityDto.Id, includeProperties: "EducationProgramClassTypes.ClassType");

                var currentClassTypes = entity.EducationProgramClassTypes.ToList();

                var newClassTypes = entityDto.ClassTypeIds;

                var classTypesToRemove = currentClassTypes
                                         .Where(cet => !newClassTypes.Contains(cet.Id))
                                         .Select(sf => new EducationProgramClassTypeDto
                {
                    Id                 = sf.Id,
                    ClassTypeId        = sf.ClassTypeId,
                    EducationProgramId = entityDto.Id
                }).ToList();

                var classTypesToAdd = newClassTypes
                                      .Where(nt => !currentClassTypes.Select(cct => cct.Id).Contains(nt))
                                      .Select(sf => new EducationProgramClassTypeDto
                {
                    ClassTypeId        = sf,
                    EducationProgramId = entityDto.Id
                }).ToList();

                if ((await RemoveClassTypes(classTypesToRemove))
                    .IsNotSuccess(out ActionResponse <List <EducationProgramClassTypeDto> > removeResponse))
                {
                    return(await ActionResponse <EducationProgramDto> .ReturnError("Neuspješno micanje tipova nastave s edukacijskog programa."));
                }

                if ((await AddClassTypes(classTypesToAdd)).IsNotSuccess(out ActionResponse <List <EducationProgramClassTypeDto> > addResponse, out classTypesToAdd))
                {
                    return(await ActionResponse <EducationProgramDto> .ReturnError("Neuspješno dodavanje tipova nastave edukacijskom programu."));
                }
                return(await ActionResponse <EducationProgramDto> .ReturnSuccess(entityDto, "Uspješno izmijenjeni tipovi nastave edukacijskog programa."));
            }
            catch (Exception)
            {
                return(await ActionResponse <EducationProgramDto> .ReturnError("Greška prilikom izmjene tipova nastave edukacijskog programa."));
            }
        }
Ejemplo n.º 10
0
        public async Task <ActionResponse <List <StudentDto> > > GetTenNewest()
        {
            try
            {
                var cachedResponse = await cacheService.GetFromCache <List <StudentDto> >();

                if (!cachedResponse.IsSuccessAndHasData(out List <StudentDto> students))
                {
                    students = (await GetAll()).GetData();
                }

                return(await ActionResponse <List <StudentDto> > .ReturnSuccess(students.OrderByDescending(s => s.DateCreated).Take(10).ToList()));
            }
            catch (Exception)
            {
                return(await ActionResponse <List <StudentDto> > .ReturnError("Greška prilikom dohvata deset najnovijih studenata."));
            }
        }
Ejemplo n.º 11
0
        private async Task <ActionResponse <List <StudentRegisterEntryDto> > > GetEntriesForStudentAndProgram(StudentRegisterEntryInsertRequest request)
        {
            try
            {
                var insertedStudents = unitOfWork.GetGenericRepository <StudentRegisterEntry>()
                                       .ReadAllActiveAsQueryable()
                                       .Where(sre => sre.EducationProgramId == request.EducationProgramId.Value &&
                                              sre.StudentsInGroups.StudentId == request.StudentId.Value &&
                                              sre.Status == DatabaseEntityStatusEnum.Active)
                                       .ToList();

                return(await ActionResponse <List <StudentRegisterEntryDto> > .ReturnSuccess(mapper.Map <List <StudentRegisterEntryDto> >(insertedStudents)));
            }
            catch (Exception)
            {
                return(await ActionResponse <List <StudentRegisterEntryDto> > .ReturnError("Greška prilikom dohvata zapisa koji sadrže traženi program i studenta."));
            }
        }
Ejemplo n.º 12
0
        public async Task <ActionResponse <List <ClassLocationsDto> > > GetAllForCache()
        {
            try
            {
                var query = unitOfWork.GetGenericRepository <ClassLocations>()
                            .ReadAll();

                var classLocations = mapper.ProjectTo <ClassLocationsDto>(query).ToList();

                await locationService.AttachLocations(classLocations);

                return(await ActionResponse <List <ClassLocationsDto> > .ReturnSuccess(classLocations));
            }
            catch (Exception)
            {
                return(await ActionResponse <List <ClassLocationsDto> > .ReturnError("Greška prilikom dohvata mjesta izvođenja za brzu memoriju."));
            }
        }
Ejemplo n.º 13
0
        public async Task <ActionResponse <TeacherViewModel> > CreateTeacher(TeacherViewModel request)
        {
            try
            {
                if (!request.UserId.HasValue)
                {
                    return(await ActionResponse <TeacherViewModel> .ReturnError("Molimo, povežite nastavnika na postojećeg korisnika."));
                }

                using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
                {
                    if ((await UpdateTeacher(request))
                        .IsNotSuccess(out ActionResponse <TeacherViewModel> actionResponse, out request))
                    {
                        return(actionResponse);
                    }

                    var rolesRequest = new UserViewModel
                    {
                        Id         = request.UserId,
                        RolesNamed = new List <string> {
                            "Nastavnik"
                        }
                    };

                    if ((await AddRoles(mapper.Map <UserViewModel>(rolesRequest)))
                        .IsNotSuccess(out ActionResponse <UserViewModel> rolesResponse, out UserViewModel viewModel))
                    {
                        return(await ActionResponse <TeacherViewModel>
                               .ReturnError("Dogodila se greška prilikom dodavanja role nastavnika za korisnika."));
                    }
                    scope.Complete();
                }
                return(await ActionResponse <TeacherViewModel> .ReturnSuccess(request, "Korisnik uspješno dodan u rolu nastavnika i njegovi detelji ažurirani."));
            }
            catch (Exception)
            {
                return(await ActionResponse <TeacherViewModel> .ReturnError("Greška prilikom kreacije novog nastavnika."));
            }
            finally
            {
                await cacheService.RefreshCache <List <UserDto> >();
            }
        }
Ejemplo n.º 14
0
        public async Task <ActionResponse <List <Claim> > > GetUserClaims(UserDto user)
        {
            try
            {
                var userToVerify = await userManager.FindByNameAsync(user.UserName);

                var allClaims = await jwtFactory.GetJwtClaims(user);

                allClaims.AddRange(new List <Claim>()
                {
                    new Claim(ClaimTypes.Name, user.UserName),
                    new Claim(ClaimTypes.NameIdentifier, user.Id.ToString())
                });

                // Get additional claims linked to user, without role and get roles as well
                var userClaims = await userManager.GetClaimsAsync(userToVerify);

                allClaims.AddRange(userClaims);

                var userRoles = await userManager.GetRolesAsync(userToVerify);

                foreach (var userRole in userRoles)
                {
                    allClaims.Add(new Claim(ClaimTypes.Role, userRole));
                    var role = await roleManager.FindByNameAsync(userRole);

                    if (role != null)
                    {
                        var roleClaims = await roleManager.GetClaimsAsync(role);

                        foreach (Claim roleClaim in roleClaims)
                        {
                            allClaims.Add(roleClaim);
                        }
                    }
                }

                return(await ActionResponse <List <Claim> > .ReturnSuccess(allClaims));
            }
            catch (Exception ex)
            {
                return(await ActionResponse <List <Claim> > .ReturnError(ex.Message));
            }
        }
Ejemplo n.º 15
0
        private async Task <ActionResponse <PlanDto> > ModifyPlanDays(PlanDto plan)
        {
            try
            {
                var entity = unitOfWork.GetGenericRepository <Plan>()
                             .FindBy(p => p.Id == plan.Id, includeProperties: "PlanDays.Subjects.PlanDaySubjectThemes.Theme");
                plan.PlanDaysId = null;

                var currentDays = mapper.Map <List <PlanDay>, List <PlanDayDto> >(entity.PlanDays.ToList());

                var newDays = plan.PlanDays;

                var daysToRemove = currentDays.Where(cd => !newDays.Select(nd => nd.Id).Contains(cd.Id)).ToList();

                var daysToAdd = newDays
                                .Where(nt => !currentDays.Select(cd => cd.Id).Contains(nt.Id))
                                .Select(pd => { pd.PlanId = plan.Id; return(pd); })
                                .ToList();

                var daysToModify = newDays.Where(cd => currentDays.Select(nd => nd.Id).Contains(cd.Id)).ToList();

                if ((await RemoveDaysFromPlan(daysToRemove))
                    .IsNotSuccess(out ActionResponse <List <PlanDayDto> > actionResponse))
                {
                    return(await ActionResponse <PlanDto> .ReturnError("Neuspješno ažuriranje dana u planu."));
                }

                if ((await AddDaysToPlan(daysToAdd)).IsNotSuccess(out actionResponse))
                {
                    return(await ActionResponse <PlanDto> .ReturnError("Neuspješno ažuriranje dana u planu."));
                }

                if ((await ModifyDaysInPlan(daysToModify)).IsNotSuccess(out actionResponse))
                {
                    return(await ActionResponse <PlanDto> .ReturnError("Neuspješno ažuriranje dana u planu."));
                }

                return(await ActionResponse <PlanDto> .ReturnSuccess(plan, "Uspješno izmijenjeni dani plana."));
            }
            catch (Exception)
            {
                return(await ActionResponse <PlanDto> .ReturnError("Greška prilikom modifikacije dana za plan."));
            }
        }
Ejemplo n.º 16
0
        public async Task <ActionResponse <UserViewModel> > AddRoles(UserViewModel user)
        {
            try
            {
                var entity = await userManager.FindByIdAsync(user.Id.Value.ToString());

                var result = await userManager.AddToRolesAsync(entity, user.RolesNamed);

                if (!result.Succeeded && !result.Errors.Any(e => e.Code == "UserAlreadyInRole"))
                {
                    return(await ActionResponse <UserViewModel> .ReturnError("Greška prilikom dodavanja rola korisniku."));
                }
                return(await ActionResponse <UserViewModel> .ReturnSuccess(user));
            }
            catch (Exception)
            {
                return(await ActionResponse <UserViewModel> .ReturnError("Greška prilikom dodavanja rola korisniku."));
            }
        }
Ejemplo n.º 17
0
        public async Task <ActionResponse <List <UserViewModel> > > GetAllUsersFE()
        {
            try
            {
                List <UserDto> users = new List <UserDto>();
                var            cachedUsersResponse = await cacheService.GetFromCache <List <UserDto> >();

                if (!cachedUsersResponse.IsSuccessAndHasData(out users))
                {
                    users = (await GetAllUsers()).GetData();
                }
                var feUsers = mapper.Map <List <UserDto>, List <UserViewModel> >(users);
                return(await ActionResponse <List <UserViewModel> > .ReturnSuccess(feUsers));
            }
            catch (Exception)
            {
                return(await ActionResponse <List <UserViewModel> > .ReturnError("Greška prilikom dohvata podataka za korisnike."));
            }
        }
Ejemplo n.º 18
0
        private async Task <ActionResponse <StudentRegisterEntryDto> > GetEntryForStudentNumberAndBookNumberAndBookYear(StudentRegisterEntryInsertRequest request)
        {
            try
            {
                var insertedStudent = unitOfWork.GetGenericRepository <StudentRegisterEntry>()
                                      .ReadAllActiveAsQueryable()
                                      .Where(sre => sre.StudentRegisterNumber == request.StudentRegisterNumber &&
                                             sre.StudentRegister.BookNumber == request.BookNumber &&
                                             sre.StudentRegister.BookYear == request.BookYear &&
                                             sre.Status == DatabaseEntityStatusEnum.Active)
                                      .FirstOrDefault();

                return(await ActionResponse <StudentRegisterEntryDto> .ReturnSuccess(mapper.Map <StudentRegisterEntryDto>(insertedStudent)));
            }
            catch (Exception)
            {
                return(await ActionResponse <StudentRegisterEntryDto> .ReturnError("Greška prilikom dohvata zapisa po knjizi i broju studenta."));
            }
        }
Ejemplo n.º 19
0
        public async Task <ActionResponse <UserViewModel> > RemoveRoles(UserViewModel user)
        {
            try
            {
                var entity = await userManager.FindByIdAsync(user.Id.Value.ToString());

                var result = await userManager.RemoveFromRolesAsync(entity, user.RolesNamed);

                if (!result.Succeeded)
                {
                    return(await ActionResponse <UserViewModel> .ReturnError("Failed to remove from roles"));
                }
                return(await ActionResponse <UserViewModel> .ReturnSuccess(user));
            }
            catch (Exception)
            {
                return(await ActionResponse <UserViewModel> .ReturnError("Greška prilikom micanja rola s korisnika."));
            }
        }
Ejemplo n.º 20
0
        public async Task <ActionResponse <UserViewModel> > UpdateUserDetails(UserViewModel userDetails)
        {
            try
            {
                var userDetailsEntity = unitOfWork.GetGenericRepository <UserDetails>().FindBy(ud => ud.Id == userDetails.UserDetailsId);
                userDetailsEntity.FirstName   = userDetails.FirstName;
                userDetailsEntity.LastName    = userDetails.LastName;
                userDetailsEntity.Mobile      = userDetails.Mobile;
                userDetailsEntity.Mobile2     = userDetails.Mobile2;
                userDetailsEntity.Phone       = userDetails.Phone;
                userDetailsEntity.Title       = userDetails.Title;
                userDetailsEntity.TitlePrefix = userDetails.TitlePrefix;

                if (userDetails.Avatar != null)
                {
                    userDetailsEntity.AvatarId = userDetails.Avatar.Id.Value;
                }
                else
                {
                    userDetailsEntity.Avatar   = null;
                    userDetailsEntity.AvatarId = null;
                }

                if (userDetails.Signature != null)
                {
                    userDetailsEntity.SignatureId = userDetails.Signature.Id.Value;
                }
                else
                {
                    userDetailsEntity.Signature   = null;
                    userDetailsEntity.SignatureId = null;
                }

                unitOfWork.GetGenericRepository <UserDetails>().Update(userDetailsEntity);
                unitOfWork.Save();
                return(await ActionResponse <UserViewModel> .ReturnSuccess(userDetails));
            }
            catch (Exception)
            {
                return(await ActionResponse <UserViewModel>
                       .ReturnError("Dogodila se greška prilikom ažuriranja podataka o korisniku. Molimo pokušajte ponovno."));
            }
        }
Ejemplo n.º 21
0
        public async Task <ActionResponse <ClassLocationsDto> > GetById(int id)
        {
            try
            {
                var query = unitOfWork.GetGenericRepository <ClassLocations>()
                            .ReadAll()
                            .Where(e => e.Id == id);

                var entities = mapper.ProjectTo <ClassLocationsDto>(query).ToList();

                await locationService.AttachLocations(entities);

                return(await ActionResponse <ClassLocationsDto> .ReturnSuccess(entities.Single()));
            }
            catch (Exception)
            {
                return(await ActionResponse <ClassLocationsDto> .ReturnError("Greška prilikom dohvata mjesta izvođenja."));
            }
        }
Ejemplo n.º 22
0
        public async Task <ActionResponse <ClassLocationsDto> > Delete(int id)
        {
            try
            {
                unitOfWork.GetGenericRepository <ClassLocations>().Delete(id);
                unitOfWork.Save();
                await cacheService.RefreshCache <List <ClassLocationsDto> >();

                return(await ActionResponse <ClassLocationsDto> .ReturnSuccess(null, "Brisanje mjesta izvođenja uspješno."));
            }
            catch (Exception)
            {
                return(await ActionResponse <ClassLocationsDto> .ReturnError("Greška prilikom brisanja mjesta izvođenja!"));
            }
            finally
            {
                await cacheService.RefreshCache <List <ClassLocationsDto> >();
            }
        }
Ejemplo n.º 23
0
        private async Task <ActionResponse <StudentDto> > CheckForDelete(int id)
        {
            try
            {
                var checkQuery = unitOfWork.GetGenericRepository <StudentClassAttendance>()
                                 .ReadAllActiveAsQueryable()
                                 .Where(e => e.StudentId == id);

                if (checkQuery.Any())
                {
                    return(await ActionResponse <StudentDto> .ReturnWarning(null, "error.delete_linked_data"));
                }

                return(await ActionResponse <StudentDto> .ReturnSuccess(null, "Brisanje moguće."));
            }
            catch (Exception)
            {
                return(await ActionResponse <StudentDto> .ReturnError("Greška prilikom provjere za brisanja studenta."));
            }
        }
Ejemplo n.º 24
0
        public async Task <ActionResponse <StudentRegisterDto> > Update(StudentRegisterDto entityDto)
        {
            try
            {
                using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
                {
                    var entityToUpdate = mapper.Map <StudentRegisterDto, StudentRegister>(entityDto);
                    unitOfWork.GetGenericRepository <StudentRegister>().Update(entityToUpdate);
                    unitOfWork.Save();

                    scope.Complete();

                    return(await ActionResponse <StudentRegisterDto> .ReturnSuccess(mapper.Map(entityToUpdate, entityDto)));
                }
            }
            catch (Exception)
            {
                return(await ActionResponse <StudentRegisterDto> .ReturnError("Greška prilikom upisa matične knjige."));
            }
        }
        public async Task <ActionResponse <UserExamCommissionDto> > ModifyCommissionMember(UserExamCommissionDto member)
        {
            try
            {
                var entityToModify = mapper.Map <UserExamCommissionDto, UserExamCommission>(member);
                unitOfWork.GetGenericRepository <UserExamCommission>().Update(entityToModify);
                unitOfWork.Save();

                mapper.Map(entityToModify, member);

                unitOfWork.GetContext().Entry(entityToModify).State = EntityState.Detached;
                entityToModify = null;

                return(await ActionResponse <UserExamCommissionDto> .ReturnSuccess(member, "Član komisije uspješno ažuriran."));
            }
            catch (Exception)
            {
                return(await ActionResponse <UserExamCommissionDto> .ReturnError("Greška prilikom ažuriranja člana ispitne komisije."));
            }
        }
Ejemplo n.º 26
0
        public async Task <ActionResponse <StudentRegisterEntryDto> > DeleteEntry(int id)
        {
            try
            {
                unitOfWork.GetGenericRepository <StudentRegisterEntry>().Delete(id);
                unitOfWork.Save();

                //await cacheService.RefreshCache<List<StudentRegisterEntryDto>>();

                return(await ActionResponse <StudentRegisterEntryDto> .ReturnSuccess(null, "Brisanje zapisa iz matične knjige uspješno."));
            }
            catch (Exception)
            {
                return(await ActionResponse <StudentRegisterEntryDto> .ReturnError("Greška prilikom brisanja zapisa u matičnoj knjizi."));
            }
            //finally
            //{
            //    await cacheService.RefreshCache<List<StudentRegisterEntryDto>>();
            //}
        }
        public async Task <ActionResponse <GoverningCouncilMemberDto> > UpdateCouncilMember(GoverningCouncilMemberDto member)
        {
            try
            {
                var entityToModify = mapper.Map <GoverningCouncilMemberDto, GoverningCouncilMember>(member);
                unitOfWork.GetGenericRepository <GoverningCouncilMember>().Update(entityToModify);
                unitOfWork.Save();

                mapper.Map(entityToModify, member);

                unitOfWork.GetContext().Entry(entityToModify).State = EntityState.Detached;
                entityToModify = null;

                return(await ActionResponse <GoverningCouncilMemberDto> .ReturnSuccess(member, "Član upravnog vijeća uspješno ažuriran."));
            }
            catch (Exception)
            {
                return(await ActionResponse <GoverningCouncilMemberDto> .ReturnError("Greška prilikom ažuriranja člana upravnog vijeća."));
            }
        }
Ejemplo n.º 28
0
        public async Task <ActionResponse <object> > ChangePassword(UserChangePasswordDto passwordDto)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(passwordDto.Email) || string.IsNullOrWhiteSpace(passwordDto.NewPassword))
                {
                    return(await ActionResponse <object> .ReturnError("Dio obaveznih parametara nedostaje. Izmjena nije moguća."));
                }

                var user = await userManager.FindByEmailAsync(passwordDto.Email);

                if (user == null)
                {
                    return(await ActionResponse <object> .ReturnError("Korisnik sa odabranom email adresom ne postoji u sustavu."));
                }

                var validator = userManager.PasswordValidators.First();
                var isValid   = await validator.ValidateAsync(userManager, user, passwordDto.NewPassword);

                if (!isValid.Succeeded)
                {
                    return(await ActionResponse <object>
                           .ReturnError("Odabrana lozinka ne odgovara standardima. Lozinka mora imati barem jedan poseban znak, jedan broj i kombinaciju malih i velikih slova."));
                }

                var resetToken = await userManager.GeneratePasswordResetTokenAsync(user);

                var result = await userManager.ResetPasswordAsync(user, resetToken, passwordDto.NewPassword);

                if (!result.Succeeded)
                {
                    return(await ActionResponse <object> .ReturnError("Greška prilikom izmjene lozinke. Molimo pokušajte ponovno ili kontaktirajte administratore."));
                }

                return(await ActionResponse <object> .ReturnSuccess(null, "Lozinka uspješno izmijenjena."));
            }
            catch (Exception)
            {
                return(await ActionResponse <object> .ReturnError("Nepredviđena greška prilikom izmjene lozinke. Molimo pokušajte ponovno ili kontaktirajte administratore."));
            }
        }
        public async Task <ActionResponse <GoverningCouncilMemberDto> > AddCouncilMember(GoverningCouncilMemberDto entityDto)
        {
            try
            {
                var entityToAdd = mapper.Map <GoverningCouncilMemberDto, GoverningCouncilMember>(entityDto);
                unitOfWork.GetGenericRepository <GoverningCouncilMember>().Add(entityToAdd);
                unitOfWork.Save();

                mapper.Map(entityToAdd, entityDto);

                unitOfWork.GetContext().Entry(entityToAdd).State = EntityState.Detached;
                entityToAdd = null;

                return(await ActionResponse <GoverningCouncilMemberDto>
                       .ReturnSuccess(entityDto, "Novi član uspješno dodan u upravno vijeće."));
            }
            catch (Exception)
            {
                return(await ActionResponse <GoverningCouncilMemberDto> .ReturnError("Greška prilikom dodavanja člana u upravno vijeće."));
            }
        }
Ejemplo n.º 30
0
        public async Task <ActionResponse <PagedResult <ClassTypeDto> > > GetAllClassTypesPaged(BasePagedRequest pagedRequest)
        {
            try
            {
                List <ClassTypeDto> classTypes = new List <ClassTypeDto>();
                var cachedResponse             = await cacheService.GetFromCache <List <ClassTypeDto> >();

                if (!cachedResponse.IsSuccessAndHasData(out classTypes))
                {
                    classTypes = (await GetAll()).GetData();
                }

                var pagedResult = await classTypes.AsQueryable().GetPaged(pagedRequest);

                return(await ActionResponse <PagedResult <ClassTypeDto> > .ReturnSuccess(pagedResult));
            }
            catch (Exception)
            {
                return(await ActionResponse <PagedResult <ClassTypeDto> > .ReturnError("Greška prilikom dohvata straničnih podataka vrsta nastave."));
            }
        }