Esempio n. 1
0
        public async Task <ActionResponse <PlanDaySubjectDto> > ModifyPlanDaySubject(PlanDaySubjectDto entityDto)
        {
            try
            {
                List <PlanDaySubjectThemeDto> planDaySubjectThemes = new List <PlanDaySubjectThemeDto>(entityDto.PlanDaySubjectThemes);
                entityDto.PlanDaySubjectThemeIds = null;
                entityDto.PlanDaySubjectThemes   = null;

                var entityToUpdate = unitOfWork.GetGenericRepository <PlanDaySubject>().FindSingle(entityDto.Id.Value);
                mapper.Map(entityDto, entityToUpdate);
                unitOfWork.GetGenericRepository <PlanDaySubject>().Update(entityToUpdate);
                unitOfWork.Save();

                entityDto.PlanDaySubjectThemes = planDaySubjectThemes;
                if ((await ModifyPlanDaySubjectsThemes(entityDto))
                    .IsNotSuccess(out ActionResponse <PlanDaySubjectDto> themesResponse, out entityDto))
                {
                    return(themesResponse);
                }

                return(await ActionResponse <PlanDaySubjectDto>
                       .ReturnSuccess(mapper.Map(entityToUpdate, entityDto), "Predmet u danu plana uspješno ažuriran."));
            }
            catch (Exception)
            {
                return(await ActionResponse <PlanDaySubjectDto> .ReturnError("Greška prilikom ažuriranja predmeta u danu plana."));
            }
        }
Esempio n. 2
0
        public async Task <ActionResponse <IssuedPrintDto> > Increment(IssuedPrintDto entityDto)
        {
            try
            {
                var targetYear = new DateTime(entityDto.PrintDate.Year, 1, 1);

                var entityToUpdate = unitOfWork.GetGenericRepository <IssuedPrint>()
                                     .GetAllAsQueryable()
                                     .Where(e => e.StudentId == entityDto.StudentId &&
                                            e.EducationProgramId == entityDto.EducationProgramId &&
                                            e.DateCreated >= targetYear && e.DateCreated <= targetYear.AddYears(1).AddTicks(-1))
                                     .FirstOrDefault();

                entityToUpdate.PrintNumber += 1;

                unitOfWork.Save();

                return(await ActionResponse <IssuedPrintDto>
                       .ReturnSuccess(mapper.Map <IssuedPrint, IssuedPrintDto>(entityToUpdate)));
            }
            catch (Exception)
            {
                return(await ActionResponse <IssuedPrintDto> .ReturnError("Greška prilikom inkrementa izdanog printa."));
            }
        }
Esempio n. 3
0
        public async Task <ActionResponse <PlanDayDto> > UpdatePlanDay(PlanDayDto entityDto)
        {
            try
            {
                List <PlanDaySubjectDto> planDaySubjects = new List <PlanDaySubjectDto>(entityDto.PlanDaySubjects);
                entityDto.PlanDaySubjectIds = null;
                entityDto.PlanDaySubjects   = null;

                var entityToUpdate = unitOfWork.GetGenericRepository <PlanDay>().FindSingle(entityDto.Id.Value);
                mapper.Map(entityDto, entityToUpdate);
                unitOfWork.GetGenericRepository <PlanDay>().Update(entityToUpdate);
                unitOfWork.Save();

                entityDto.PlanDaySubjects = planDaySubjects.Select(pd =>
                {
                    pd.PlanDayId = entityDto.Id;
                    return(pd);
                }).ToList();

                if ((await ModifyPlanDaySubjects(entityDto)).IsNotSuccess(out ActionResponse <PlanDayDto> response, out entityDto))
                {
                    return(response);
                }

                return(await ActionResponse <PlanDayDto>
                       .ReturnSuccess(mapper.Map(entityToUpdate, entityDto)));
            }
            catch (Exception)
            {
                return(await ActionResponse <PlanDayDto> .ReturnError("Greška prilikom ažuriranja dana plana."));
            }
        }
Esempio n. 4
0
        public async Task <ActionResponse <PlanDaySubjectDto> > InsertPlanDaySubject(PlanDaySubjectDto entityDto)
        {
            try
            {
                List <PlanDaySubjectThemeDto> planDaySubjectThemes = new List <PlanDaySubjectThemeDto>(entityDto.PlanDaySubjectThemes);
                entityDto.PlanDaySubjectThemeIds = null;
                entityDto.PlanDaySubjectThemes   = null;

                var entityToAdd = mapper.Map <PlanDaySubjectDto, PlanDaySubject>(entityDto);
                unitOfWork.GetGenericRepository <PlanDaySubject>().Add(entityToAdd);
                unitOfWork.Save();
                mapper.Map(entityToAdd, entityDto);

                entityDto.PlanDaySubjectThemes = planDaySubjectThemes.Select(pd =>
                {
                    pd.PlanDaySubjectId = entityDto.Id;
                    return(pd);
                }).ToList();

                if ((await ModifyPlanDaySubjectsThemes(entityDto))
                    .IsNotSuccess(out ActionResponse <PlanDaySubjectDto> themesResponse, out entityDto))
                {
                    return(themesResponse);
                }

                return(await ActionResponse <PlanDaySubjectDto> .ReturnSuccess(entityDto, "Predmet uspješno dodan u dan plana."));
            }
            catch (Exception)
            {
                return(await ActionResponse <PlanDaySubjectDto> .ReturnError("Greška prilikom dodavanja predmeta u dan plana."));
            }
        }
Esempio n. 5
0
        public async Task <ActionResponse <PlanDayDto> > AddDayToPlan(PlanDayDto entityDto)
        {
            try
            {
                List <PlanDaySubjectDto> planDaySubjects = new List <PlanDaySubjectDto>(entityDto.PlanDaySubjects);
                entityDto.PlanDaySubjectIds = null;
                entityDto.PlanDaySubjects   = null;

                var entityToAdd = mapper.Map <PlanDayDto, PlanDay>(entityDto);
                unitOfWork.GetGenericRepository <PlanDay>().Add(entityToAdd);
                unitOfWork.Save();
                mapper.Map(entityToAdd, entityDto);

                entityDto.PlanDaySubjects = planDaySubjects.Select(pd =>
                {
                    pd.PlanDayId = entityDto.Id;
                    return(pd);
                }).ToList();

                if ((await ModifyPlanDaySubjects(entityDto)).IsNotSuccess(out ActionResponse <PlanDayDto> response, out entityDto))
                {
                    return(response);
                }

                return(await ActionResponse <PlanDayDto> .ReturnSuccess(mapper.Map(entityToAdd, entityDto), "Dan plana uspješno unesen."));
            }
            catch (Exception)
            {
                return(await ActionResponse <PlanDayDto> .ReturnError("Greška prilikom dodavanja dana u plan."));
            }
        }
Esempio n. 6
0
        public async Task <ActionResponse <PlanDto> > Update(PlanDto entityDto)
        {
            try
            {
                List <PlanDayDto> planDays = new List <PlanDayDto>(entityDto.PlanDays);
                entityDto.PlanDays   = null;
                entityDto.PlanDaysId = null;

                var entityToUpdate = mapper.Map <PlanDto, Plan>(entityDto);
                unitOfWork.GetGenericRepository <Plan>().Update(entityToUpdate);
                unitOfWork.Save();

                entityDto.PlanDays = planDays;
                if ((await ModifyPlanDays(entityDto))
                    .IsNotSuccess(out ActionResponse <PlanDto> modifyDaysResponse, out entityDto))
                {
                    return(modifyDaysResponse);
                }

                if ((await GetById(entityToUpdate.Id)).IsNotSuccess(out ActionResponse <PlanDto> getResponse, out entityDto))
                {
                    return(await ActionResponse <PlanDto> .ReturnError("Greška prilikom ažuriranja podataka za plan."));
                }

                return(await ActionResponse <PlanDto> .ReturnSuccess(entityDto, "Plan uspješno ažuriran."));
            }
            catch (Exception)
            {
                return(await ActionResponse <PlanDto> .ReturnError("Greška prilikom ažuriranja plana."));
            }
        }
Esempio n. 7
0
        public async Task <ActionResponse <UserViewModel> > Update(UserViewModel request)
        {
            try
            {
                if (!request.Id.HasValue || !request.UserDetailsId.HasValue)
                {
                    return(await ActionResponse <UserViewModel> .ReturnError("Incorect primary key so unable to update."));
                }

                if ((await userDetailsService.UpdateUserDetails(request))
                    .IsNotSuccess(out ActionResponse <UserViewModel> response, out request))
                {
                    return(await ActionResponse <UserViewModel> .ReturnError(response.Message, request));
                }

                unitOfWork.Save();

                if ((await ModifyUserRoles(request)).IsNotSuccess(out response))
                {
                    return(response);
                }

                return(await ActionResponse <UserViewModel> .ReturnSuccess(request, "User updated successfully."));
            }
            catch (Exception)
            {
                return(await ActionResponse <UserViewModel> .ReturnError("Greška prilikom ažuriranja podataka korisnika."));
            }
            finally
            {
                await cacheService.RefreshCache <List <UserDto> >();
            }
        }
Esempio n. 8
0
        public async Task <ActionResponse <List <ClassLocationsDto> > > GetAll()
        {
            try
            {
                var allOfThem      = new List <ClassLocationsDto>();
                var cachedResponse = await cacheService.GetFromCache <List <ClassLocationsDto> >();

                if (cachedResponse.IsSuccessAndHasData(out allOfThem))
                {
                    return(await ActionResponse <List <ClassLocationsDto> > .ReturnSuccess(allOfThem));
                }

                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 svih mjesta izvođenja."));
            }
        }
Esempio n. 9
0
        public async Task <ActionResponse <LoginResponse> > Login(LoginRequest loginRequest)
        {
            try
            {
                var userToLogin = await userManager.FindByEmailAsync(loginRequest.Email);

                if (userToLogin == null)
                {
                    return(await ActionResponse <LoginResponse> .ReturnError("Ne postoji korisnik registriran s tom email adresom."));
                }

                var result = await signInManager.PasswordSignInAsync(userToLogin, loginRequest.Password, true, true);

                if (result.Succeeded)
                {
                    var user = mapper.Map <UserDto>(userToLogin);
                    user.Claims = (await userService.GetUserClaims(user)).GetData();
                    var jwtToken = await jwtFactory.GenerateSecurityToken(user, loginRequest.RememberMe);

                    return(await ActionResponse <LoginResponse> .ReturnSuccess(new LoginResponse
                    {
                        UserId = user.Id.Value,
                        JwtToken = jwtToken.Token,
                        ValidUntil = jwtToken.ValidUntil
                    }, "Successfully logged in!"));
                }
                return(await ActionResponse <LoginResponse> .ReturnError("Pogrešno korisničko ime ili lozinka."));
            }
            catch (Exception)
            {
                return(await ActionResponse <LoginResponse> .ReturnError("Dogodila se kritična greška. Molimo kontaktirajte administratore."));
            }
        }
Esempio n. 10
0
        public async Task <ActionResponse <PagedResult <TeacherViewModel> > > GetAllTeachersPaged(BasePagedRequest pagedRequest)
        {
            try
            {
                List <UserDto> users = new List <UserDto>();
                var            cachedUsersResponse = await cacheService.GetFromCache <List <UserDto> >();

                if (!cachedUsersResponse.IsSuccessAndHasData(out users))
                {
                    users = (await GetAllUsers()).GetData();
                }

                var teacherUsers = mapper.Map <List <UserDto>, List <TeacherViewModel> >(
                    users
                    .Where(u => u.UserRoles.Any(ur => ur.Name == "Nastavnik"))
                    .ToList());

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

                return(await ActionResponse <PagedResult <TeacherViewModel> > .ReturnSuccess(pagedResult));
            }
            catch (Exception)
            {
                return(await ActionResponse <PagedResult <TeacherViewModel> > .ReturnError("Greška prilikom dohvata straničnih podataka nastavnika."));
            }
        }
Esempio n. 11
0
        public async Task <ActionResponse <object> > DeleteTeacher(UserGetRequest request)
        {
            try
            {
                using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
                {
                    var rolesRequest = new UserViewModel
                    {
                        Id         = request.Id,
                        RolesNamed = new List <string> {
                            "Nastavnik"
                        }
                    };

                    if ((await RemoveRoles(mapper.Map <UserViewModel>(rolesRequest)))
                        .IsNotSuccess(out ActionResponse <UserViewModel> rolesResponse, out UserViewModel viewModel))
                    {
                        return(await ActionResponse <object>
                               .ReturnError("Dogodila se greška prilikom brisanja role nastavnika za korisnika. Molimo pokušajte ponovno."));
                    }
                    scope.Complete();
                }
                return(await ActionResponse <object> .ReturnSuccess(null, "Nastavnik uspješno izbrisan!"));
            }
            catch (Exception)
            {
                return(await ActionResponse <object> .ReturnError("Greška prilikom brisanja nastavnika."));
            }
            finally
            {
                await cacheService.RefreshCache <List <UserDto> >();
            }
        }
Esempio n. 12
0
        public async Task <ActionResponse <StudentDto> > Insert(StudentDto entityDto)
        {
            try
            {
                List <FileDto> files = entityDto.Files != null ? new List <FileDto>(entityDto.Files) : new List <FileDto>();
                entityDto.Files = null;

                var entityToAdd = mapper.Map <StudentDto, Student>(entityDto);
                unitOfWork.GetGenericRepository <Student>().Add(entityToAdd);
                unitOfWork.Save();

                mapper.Map(entityToAdd, entityDto);
                entityDto.Files = files;
                if ((await ModifyStudentFiles(entityDto))
                    .IsNotSuccess(out ActionResponse <StudentDto> fileResponse, out entityDto))
                {
                    return(fileResponse);
                }

                await cacheService.RefreshCache <List <StudentDto> >();

                if ((await cacheService.GetFromCache <List <StudentDto> >())
                    .IsNotSuccess(out ActionResponse <List <StudentDto> > cacheResponse,
                                  out List <StudentDto> students))
                {
                    return(await ActionResponse <StudentDto> .ReturnError("Greška prilikom povrata podataka studenta."));
                }

                return(await ActionResponse <StudentDto> .ReturnSuccess(students.FirstOrDefault(s => s.Id == entityDto.Id)));
            }
            catch (Exception)
            {
                return(await ActionResponse <StudentDto> .ReturnError("Greška prilikom upisa studenta."));
            }
        }
Esempio n. 13
0
        public async Task <ActionResponse <StudentRegisterEntryDto> > UpdateEntry(StudentRegisterEntryInsertRequest request)
        {
            try
            {
                var entityToUpdate = unitOfWork.GetGenericRepository <StudentRegisterEntry>().FindSingle(request.EntryId.Value);

                entityToUpdate.Notes = request.Notes;
                entityToUpdate.EducationProgramId    = request.EducationProgramId.Value;
                entityToUpdate.StudentRegisterId     = request.BookId.Value;
                entityToUpdate.StudentRegisterNumber = request.StudentRegisterNumber.Value;
                entityToUpdate.EntryDate             = request.EntryDate;
                entityToUpdate.ExamDate       = request.ExamDate;
                entityToUpdate.ExamDateNumber = request.ExamDateNumber;

                unitOfWork.GetGenericRepository <StudentRegisterEntry>().Update(entityToUpdate);
                unitOfWork.Save();

                return(await GetEntryById(request.EntryId.Value));
            }
            catch (Exception)
            {
                return(await ActionResponse <StudentRegisterEntryDto> .ReturnError("Greška prilikom ažuriranja zapisa matične knjige."));
            }
            finally
            {
                //await cacheService.RefreshCache<List<StudentRegisterEntryDto>>();
            }
        }
Esempio n. 14
0
 private async Task <ActionResponse <StudentRegisterEntryDto> > GetEntryForStudentNumberAndBookNumberAndBookYearDetailed(StudentRegisterEntryInsertRequest request)
 {
     try
     {
         var insertedStudent = unitOfWork.GetGenericRepository <StudentRegisterEntry>()
                               .GetAll(sre => sre.StudentRegisterNumber == request.StudentRegisterNumber &&
                                       sre.StudentRegister.BookNumber == request.BookNumber &&
                                       sre.StudentRegister.BookYear == request.BookYear &&
                                       sre.Status == DatabaseEntityStatusEnum.Active, includeProperties: "StudentsInGroups.Student," +
                                       "StudentsInGroups.Student.CityOfBirth,StudentsInGroups.Student.CountryOfBirth,StudentsInGroups.Student.RegionOfBirth," +
                                       "StudentsInGroups.Student.MunicipalityOfBirth,StudentsInGroups.Student.AddressCountry," +
                                       "StudentsInGroups.Student.AddressCity,StudentsInGroups.Student.AddressRegion,StudentsInGroups.Student.AddressMunicipality," +
                                       "StudentsInGroups.StudentGroup," +
                                       "StudentsInGroups.StudentGroup.ClassLocation.Country, StudentsInGroups.StudentGroup.ClassLocation.Region," +
                                       "StudentsInGroups.StudentGroup.ClassLocation.Municipality, StudentsInGroups.StudentGroup.ClassLocation.City," +
                                       "EducationProgram.EducationGroup, EducationProgram.Subjects," +
                                       "StudentsInGroups.StudentGroup.Director.UserDetails, StudentsInGroups.StudentGroup.Director.UserDetails.Signature," +
                                       "StudentsInGroups.StudentGroup.EducationLeader.UserDetails, StudentsInGroups.StudentGroup.EducationLeader.UserDetails.Signature")
                               .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."));
     }
 }
Esempio n. 15
0
        public async Task <ActionResponse <StudentRegisterDto> > Delete(int id)
        {
            try
            {
                var response = await ActionResponse <StudentRegisterDto> .ReturnSuccess(null, "Matična knjiga uspješno obrisana");

                unitOfWork.GetGenericRepository <StudentRegister>().Delete(id);

                unitOfWork.GetGenericRepository <StudentRegisterEntry>()
                .GetAll(sre => sre.StudentRegisterId == id)
                .ForEach(async sre =>
                {
                    if ((await DeleteEntry(sre.Id)).IsNotSuccess(out ActionResponse <StudentRegisterEntryDto> deleteResponse))
                    {
                        response = await ActionResponse <StudentRegisterDto> .ReturnError(deleteResponse.Message);
                    }
                });

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

                unitOfWork.Save();

                return(response);
            }
            catch (Exception)
            {
                return(await ActionResponse <StudentRegisterDto> .ReturnError("Greška prilikom brisanja matične knjige."));
            }
        }
Esempio n. 16
0
        public async Task <ActionResponse <StudentDto> > Delete(int id)
        {
            try
            {
                var response = await ActionResponse <StudentDto> .ReturnSuccess(null, "Brisanje studenta uspješno.");

                if ((await CheckForDelete(id)).IsNotSuccess(out response))
                {
                    return(response);
                }

                unitOfWork.GetGenericRepository <Student>().Delete(id);
                unitOfWork.Save();

                return(await ActionResponse <StudentDto> .ReturnSuccess(null, "Brisanje studenta uspješno."));
            }
            catch (Exception)
            {
                return(await ActionResponse <StudentDto> .ReturnError("Greška prilikom brisanja studenta."));
            }
            finally
            {
                await cacheService.RefreshCache <List <StudentDto> >();
            }
        }
Esempio n. 17
0
        public async Task <ActionResponse <DiaryDto> > Insert(DiaryDto entityDto)
        {
            try
            {
                using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
                {
                    var entityToAdd = mapper.Map <DiaryDto, Diary>(entityDto);
                    unitOfWork.GetGenericRepository <Diary>().Add(entityToAdd);
                    unitOfWork.Save();
                    mapper.Map(entityToAdd, entityDto);

                    if ((await ModifyStudentGroupsForDiary(entityDto)).IsNotSuccess(out ActionResponse <DiaryDto> response, out entityDto))
                    {
                        return(response);
                    }

                    scope.Complete();
                    return(await ActionResponse <DiaryDto>
                           .ReturnSuccess(mapper.Map(entityToAdd, entityDto)));
                }
            }
            catch (Exception)
            {
                return(await ActionResponse <DiaryDto> .ReturnError("Greška prilikom upisa dnevnika rada."));
            }
        }
        public async Task <ActionResponse <ExamCommissionDto> > Insert(ExamCommissionDto entityDto)
        {
            try
            {
                List <UserExamCommissionDto> commissionMembers = new List <UserExamCommissionDto>(entityDto.CommissionMembers);
                var entityToAdd = mapper.Map <ExamCommissionDto, ExamCommission>(entityDto);
                unitOfWork.GetGenericRepository <ExamCommission>().Add(entityToAdd);
                unitOfWork.Save();
                mapper.Map(entityToAdd, entityDto);
                entityDto.CommissionMembers = new List <UserExamCommissionDto>(commissionMembers);
                if ((await ModifyExamTeachers(entityDto)).IsNotSuccess(out ActionResponse <ExamCommissionDto> actionResponse, out entityDto))
                {
                    return(actionResponse);
                }

                if ((await GetById(entityToAdd.Id)).IsNotSuccess(out actionResponse, out entityDto))
                {
                    return(actionResponse);
                }

                return(await ActionResponse <ExamCommissionDto> .ReturnSuccess(entityDto));
            }
            catch (Exception)
            {
                return(await ActionResponse <ExamCommissionDto> .ReturnError("Greška prilikom unosa ispitne komisije."));
            }
        }
Esempio n. 19
0
        public async Task <ActionResponse <UserDetailsDto> > UpdateUserDetails(UserDetailsDto userDetails)
        {
            try
            {
                List <FileDto> teacherFiles = new List <FileDto>(userDetails.TeacherFiles);

                var entityToUpdate = unitOfWork.GetGenericRepository <UserDetails>()
                                     .FindBy(ud => ud.UserId == userDetails.UserId);
                mapper.Map(userDetails, entityToUpdate);

                unitOfWork.GetGenericRepository <UserDetails>().Update(entityToUpdate);
                unitOfWork.Save();

                userDetails = mapper.Map <UserDetails, UserDetailsDto>(entityToUpdate);
                userDetails.TeacherFiles = teacherFiles;

                if ((await ModifyFiles(userDetails))
                    .IsNotSuccess(out ActionResponse <UserDetailsDto> fileResponse, out userDetails))
                {
                    return(fileResponse);
                }

                return(await GetUserDetails(userDetails.UserId.Value));
            }
            catch (Exception)
            {
                return(await ActionResponse <UserDetailsDto>
                       .ReturnError("Dogodila se greška prilikom ažuriranja podataka o korisniku. Molimo pokušajte ponovno."));
            }
        }
Esempio n. 20
0
        public async Task <ActionResponse <T> > RefreshCache <T>()
        {
            try
            {
                var refreshMethod = Assembly.GetExecutingAssembly()
                                    .GetTypes()
                                    .SelectMany(t => t.GetMethods()
                                                .Where(m => m.GetCustomAttributes().OfType <CacheRefreshSource>()
                                                       .Any(a => a.type == typeof(T).GenericTypeArguments[0])
                                                       ).ToList())
                                    .FirstOrDefault();

                var callingClassTypeInterfaces = refreshMethod.DeclaringType.GetInterfaces();

                var caller = serviceProvider.GetService(callingClassTypeInterfaces.First());
                var result = (ActionResponse <T>)await(dynamic) refreshMethod.Invoke(caller, null);

                await SetInCache <T>(result.Data);

                return(result);
            }
            catch (Exception)
            {
                return(await ActionResponse <T> .ReturnError("Greška prilikom osvježavanja podataka u cache-u."));
            }
        }
Esempio n. 21
0
        /// <summary>
        /// Should be used with lists: await cacheService.GetFromCache<List<UserDto>>();
        /// </summary>
        /// <typeparam name="T">List of T</typeparam>
        /// <returns>List of T</returns>
        public async Task <ActionResponse <T> > GetFromCache <T>()
        {
            try
            {
                var attribute = typeof(T).GenericTypeArguments[0]
                                .GetCustomAttributes(typeof(Cached), true).FirstOrDefault() as Cached;

                if (memoryCache.TryGetValue <T>(attribute.Key, out T cachedValue))
                {
                    return(await ActionResponse <T> .ReturnSuccess(cachedValue));
                }

                var result = await RefreshCache <T>();

                if (result.ActionResponseType != ActionResponseTypeEnum.Success)
                {
                    return(await ActionResponse <T> .ReturnError("Greška prilikom osvježavanja podataka u cacheu."));
                }

                return(await GetFromCache <T>());
            }
            catch (Exception ex)
            {
                return(await ActionResponse <T> .ReturnError("Greška prilikom dohvata podataka iz cachea."));
            }
        }
Esempio n. 22
0
        public async Task <ActionResponse <BusinessPartnerDto> > Update(BusinessPartnerDto entityDto)
        {
            try
            {
                List <ContactPersonDto> contacts = entityDto.BusinessPartnerContacts != null ?
                                                   new List <ContactPersonDto>(entityDto.BusinessPartnerContacts) : new List <ContactPersonDto>();

                var entityToUpdate = mapper.Map <BusinessPartnerDto, BusinessPartner>(entityDto);
                unitOfWork.GetGenericRepository <BusinessPartner>().Update(entityToUpdate);
                unitOfWork.Save();

                mapper.Map(entityToUpdate, entityDto);
                entityDto.BusinessPartnerContacts = contacts;

                if ((await ModifyBusinessPartnerContacts(entityDto))
                    .IsNotSuccess(out ActionResponse <BusinessPartnerDto> contactResponse, out entityDto))
                {
                    return(contactResponse);
                }

                if ((await GetById(entityToUpdate.Id)).IsNotSuccess(out ActionResponse <BusinessPartnerDto> response, out entityDto))
                {
                    return(response);
                }

                return(await ActionResponse <BusinessPartnerDto> .ReturnSuccess(entityDto));
            }
            catch (Exception)
            {
                return(await ActionResponse <BusinessPartnerDto> .ReturnError("Greška prilikom ažuriranja poslovnog partnera."));
            }
        }
Esempio n. 23
0
        public async Task <ActionResponse <T> > SetInCache <T>(T cachedObject)
        {
            try
            {
                var expirationTime  = DateTime.Now.AddMinutes(expirationMinutes);
                var expirationToken = new CancellationChangeToken(
                    new CancellationTokenSource(TimeSpan.FromMinutes(expirationMinutes + .01))
                    .Token);

                var objectType = cachedObject.GetType();
                var attribute  = objectType.GenericTypeArguments[0].GetCustomAttributes(typeof(Cached), true).FirstOrDefault() as Cached;

                MemoryCacheEntryOptions cacheOptions = new MemoryCacheEntryOptions()
                                                       .SetPriority(CacheItemPriority.High)
                                                       .SetAbsoluteExpiration(expirationTime)
                                                       .AddExpirationToken(expirationToken)
                                                       .RegisterPostEvictionCallback(callback: RefreshCache <T>, state: this);

                memoryCache.Set(attribute.Key, cachedObject);
                return(await ActionResponse <T> .ReturnSuccess());
            }
            catch (Exception)
            {
                return(await ActionResponse <T> .ReturnError("Greška prilikom postavljanja podataka u cache."));
            }
        }
        public async Task <ActionResponse <GoverningCouncilDto> > UpdateGoverningCouncil(GoverningCouncilDto entityDto)
        {
            try
            {
                List <GoverningCouncilMemberDto> councilMembers = new List <GoverningCouncilMemberDto>(entityDto.GoverningCouncilMembers);

                var entityToUpdate = mapper.Map <GoverningCouncilDto, GoverningCouncil>(entityDto);
                unitOfWork.GetGenericRepository <GoverningCouncil>().Update(entityToUpdate);
                unitOfWork.Save();

                mapper.Map(entityToUpdate, entityDto);

                entityDto.GoverningCouncilMembers = councilMembers;
                if ((await ModifyCouncilMembers(entityDto))
                    .IsNotSuccess(out ActionResponse <GoverningCouncilDto> response, out entityDto))
                {
                    return(response);
                }

                return(await ActionResponse <GoverningCouncilDto> .ReturnSuccess(entityDto, "Upravno vijeće za instituciju uspješno ažurirano."));
            }
            catch (Exception)
            {
                return(await ActionResponse <GoverningCouncilDto> .ReturnError("Greška prilikom unosa podataka za upravno vijeće."));
            }
        }
Esempio n. 25
0
        //[CacheRefreshSource(typeof(StudentRegisterDto))]
        //public async Task<ActionResponse<List<StudentRegisterDto>>> GetAllForCache()
        //{
        //    try
        //    {

        //        var entities = unitOfWork.GetGenericRepository<StudentRegister>()
        //            .ReadAllActiveAsQueryable()
        //            .Include(e => e.StudentRegisterEntries)
        //                .ThenInclude(e => e.EducationProgram)
        //            .Include(e => e.StudentRegisterEntries)
        //                .ThenInclude(e => e.StudentsInGroups)
        //            .ToList();

        //        return await ActionResponse<List<StudentRegisterDto>>.ReturnSuccess(mapper.Map<List<StudentRegisterDto>>(entities));
        //    }
        //    catch (Exception)
        //    {
        //        return await ActionResponse<List<StudentRegisterDto>>.ReturnError("Greška prilikom dohvata svih matičnih knjiga.");
        //    }
        //}

        public async Task <ActionResponse <PagedResult <StudentRegisterDto> > > GetAllPaged(BasePagedRequest pagedRequest)
        {
            try
            {
                var query = unitOfWork.GetGenericRepository <StudentRegister>()
                            .ReadAllActiveAsQueryable();

                var pagedResult = await query.GetPaged(pagedRequest, true);

                var realResult = new PagedResult <StudentRegisterDto>
                {
                    CurrentPage = pagedResult.CurrentPage,
                    PageCount   = pagedResult.PageCount,
                    PageSize    = pagedResult.PageSize,
                    RowCount    = pagedResult.RowCount,
                    Results     = mapper.ProjectTo <StudentRegisterDto>(pagedResult.ResultQuery).ToList()
                };

                return(await ActionResponse <PagedResult <StudentRegisterDto> > .ReturnSuccess(realResult));
            }
            catch (Exception)
            {
                return(await ActionResponse <PagedResult <StudentRegisterDto> > .ReturnError("Greška prilikom dohvata straničnih podataka matične knjige."));
            }
        }
        public async Task <ActionResponse <ExamCommissionDto> > Update(ExamCommissionDto entityDto)
        {
            try
            {
                var entityToUpdate = mapper.Map <ExamCommissionDto, ExamCommission>(entityDto);
                unitOfWork.GetGenericRepository <ExamCommission>().Update(entityToUpdate);
                if ((await ModifyExamTeachers(entityDto)).IsNotSuccess(out ActionResponse <ExamCommissionDto> response, out entityDto))
                {
                    return(response);
                }
                unitOfWork.Save();

                if ((await GetById(entityToUpdate.Id)).IsNotSuccess(out response, out entityDto))
                {
                    return(response);
                }

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

                return(await ActionResponse <ExamCommissionDto> .ReturnSuccess(entityDto));
            }
            catch (Exception)
            {
                return(await ActionResponse <ExamCommissionDto> .ReturnError("Greška prilikom ažuriranja ispitne komisije."));
            }
        }
 public async Task <ActionResponse <int> > GetTotalNumber()
 {
     try
     {
         return(await ActionResponse <int> .ReturnSuccess(unitOfWork.GetGenericRepository <EducationLevel>().GetAllAsQueryable().Count()));
     }
     catch (Exception)
     {
         return(await ActionResponse <int> .ReturnError("Greška prilikom dohvata broja razina obrazovanja."));
     }
 }
Esempio n. 28
0
 public async Task <ActionResponse <int> > GetTotalNumber()
 {
     try
     {
         return(await ActionResponse <int> .ReturnSuccess(unitOfWork.GetGenericRepository <ClassType>().GetAllAsQueryable().Count()));
     }
     catch (Exception)
     {
         return(await ActionResponse <int> .ReturnError("Greška prilikom dohvata broja vrsta nastave."));
     }
 }
 public async Task <ActionResponse <int> > GetTotalNumber()
 {
     try
     {
         return(await ActionResponse <int> .ReturnSuccess(unitOfWork.GetGenericRepository <Subject>().GetAllAsQueryable().Count()));
     }
     catch (Exception)
     {
         return(await ActionResponse <int> .ReturnError("Greška prilikom dohvata broja ispitnih komisija."));
     }
 }
Esempio n. 30
0
 public async Task <ActionResponse <int> > GetTotalNumber()
 {
     try
     {
         return(await ActionResponse <int> .ReturnSuccess(unitOfWork.GetGenericRepository <StudentRegister>().ReadAllActiveAsQueryable().Count()));
     }
     catch (Exception)
     {
         return(await ActionResponse <int> .ReturnError("Greška prilikom dohvata broja matičnih knjiga."));
     }
 }