Esempio n. 1
0
        public async Task <Section> GetSectionAsync(Guid id)
        {
            using (IUnitOfWork unitOfWork = unitOfWorkFactory.Create())
            {
                Database.Repositories.Section.Contract.Section section = await unitOfWork.SectionRepository.GetByIDAsync(id);

                return(section.DeepCopyTo <Section>());
            }
        }
Esempio n. 2
0
        public async Task <ValidationError[]> AddSectionAsync(Section section)
        {
            using (IUnitOfWork unitOfWork = unitOfWorkFactory.Create())
            {
                Database.Repositories.Section.Contract.Section dbSection = await unitOfWork.SectionRepository.GetByNameAsync(section.Name);

                if (dbSection == null)
                {
                    unitOfWork.SectionRepository.Upsert(section.DeepCopyTo <Database.Repositories.Section.Contract.Section>());

                    await unitOfWork.SaveAsync();

                    return(new ValidationError[0]);
                }
                return(new ValidationError[1] {
                    new ValidationError()
                    {
                        Message = "Add failed! There already exists a Section instance with this name!"
                    }
                });
            }
        }
Esempio n. 3
0
        public async Task <ValidationError[]> UpdateSectionAsync(Section section)
        {
            using (IUnitOfWork unitOfWork = unitOfWorkFactory.Create())
            {
                Database.Repositories.Section.Contract.Section dbSection = await unitOfWork.SectionRepository.GetByNameAsync(section.Name);

                if (dbSection != null && dbSection.ID != section.ID)
                {
                    return new ValidationError[1] {
                               new ValidationError()
                               {
                                   Message = "Update failed! There is already a Section with this name !"
                               }
                    }
                }
                ;

                unitOfWork.SectionRepository.Upsert(section.DeepCopyTo <Qubiz.QuizEngine.Database.Repositories.Section.Contract.Section>());

                await unitOfWork.SaveAsync();

                return(new ValidationError[0]);
            }
        }
Esempio n. 4
0
        public async Task <ValidationError[]> DeleteSectionAsync(Guid id)
        {
            using (IUnitOfWork unitOfWork = unitOfWorkFactory.Create())
            {
                Database.Repositories.Section.Contract.Section section = await unitOfWork.SectionRepository.GetByIDAsync(id);

                if (section == null)
                {
                    return new ValidationError[1] {
                               new ValidationError()
                               {
                                   Message = "Deletion failed! There is no Section instance with this ID!"
                               }
                    }
                }
                ;

                unitOfWork.SectionRepository.Delete(section);

                await unitOfWork.SaveAsync();

                return(new ValidationError[0]);
            }
        }