Ejemplo n.º 1
0
        public async Task <Guid> CreateNews(NewsFm newsFm)
        {
            if (string.IsNullOrEmpty(newsFm.Title))
            {
                throw new ArgumentException($"{newsFm.Title} is null or empty.");
            }
            if (string.IsNullOrEmpty(newsFm.Content))
            {
                throw new ArgumentException($"{newsFm.Content} is null or empty.");
            }

            News news = new News()
            {
                Id = Guid.NewGuid(),
                PublicationDate = DateTime.UtcNow,
                Title           = newsFm.Title,
                Description     = newsFm.Description,
                Content         = newsFm.Content,
                ImagesIds       = newsFm.ImagesIds,
            };

            _newsDataSource.Add(news);
            await _websiteDbContext.SaveChangesAsync();

            return(news.Id);
        }
        public async Task <Guid> AddMediaContent(IFormFile formFile)
        {
            byte[] buffer = new byte[formFile.Length];
            using (Stream stream = formFile.OpenReadStream())
            {
                int receivedCount = 0;
                do
                {
                    receivedCount += await stream.ReadAsync(buffer, receivedCount, buffer.Length - receivedCount);
                }while (receivedCount != buffer.Length);
            }

            MediaContent mediaContent = new MediaContent
            {
                Id          = Guid.NewGuid(),
                FileName    = formFile.FileName,
                ContentType = formFile.ContentType,
                Content     = buffer
            };

            _mediaContentDataSource.Add(mediaContent);
            await _websiteDbContext.SaveChangesAsync();

            return(mediaContent.Id);
        }
Ejemplo n.º 3
0
        public async Task <Guid> CreateTeacher([FromBody] TeacherFm teacherFm)
        {
            Teacher teacher = new Teacher
            {
                Id             = Guid.NewGuid(),
                Surname        = teacherFm.Surname,
                Name           = teacherFm.Name,
                Patronymic     = teacherFm.Patronymic,
                Degree         = teacherFm.Degree,
                AdditionalInfo = teacherFm.AdditionalInfo,
                PictureId      = teacherFm.PictureId,
                DepartmentId   = CodeSystem.Iu2DepartmentId
            };

            _teacherDataSource.Add(teacher);
            await _websiteDbContext.SaveChangesAsync();

            return(teacher.Id);
        }
Ejemplo n.º 4
0
        public Task CreateQuestion(QuestionFm questionFm)
        {
            if (string.IsNullOrEmpty(questionFm.Contact))
            {
                throw new ArgumentException($"{questionFm.Contact} is null or empty.");
            }
            if (string.IsNullOrEmpty(questionFm.Content))
            {
                throw new ArgumentException($"{questionFm.Content} is null or empty.");
            }

            Question question = new Question()
            {
                Id             = Guid.NewGuid(),
                Date           = DateTime.UtcNow,
                Contact        = questionFm.Contact,
                QuestionerName = questionFm.QuestionerName,
                Content        = questionFm.Content
            };

            _questionDataSource.Add(question);
            return(_websiteDbContext.SaveChangesAsync());
        }
Ejemplo n.º 5
0
 ///<inheritdoc/>
 public Task CreateMediaContent(MediaContent mediaContent)
 {
     _websiteDbContext.MediaContents.Add(Convert(mediaContent));
     return(_websiteDbContext.SaveChangesAsync());
 }
Ejemplo n.º 6
0
 ///<inheritdoc/>
 public Task CreateQuestionAsync(Question question)
 {
     _websiteDbContext.Questions.Add(question);
     return(_websiteDbContext.SaveChangesAsync());
 }
Ejemplo n.º 7
0
 ///<inheritdoc/>
 public Task CreateDepartment(Department department)
 {
     _websiteDbContext.Departments.Add(DepartmentConverter.CopyData(department));
     return(_websiteDbContext.SaveChangesAsync());
 }
Ejemplo n.º 8
0
 ///<inheritdoc/>
 public Task CreateTeacher(Teacher teacher)
 {
     _websiteDbContext.Teachers.Add(TeacherConverter.CopyData(teacher));
     return(_websiteDbContext.SaveChangesAsync());
 }
Ejemplo n.º 9
0
 ///<inheritdoc/>
 public Task CreateStudent(Student student)
 {
     _websiteDbContext.Students.Add(student);
     return(_websiteDbContext.SaveChangesAsync());
 }