Esempio n. 1
0
        public async Task <ActionResult <StudentResponse> > Post(DTO.Student input, IFormFile file)
        {
            var studentExist = await _db.Students.Where(s => s.Username == input.Username).FirstOrDefaultAsync();

            if (studentExist != null)
            {
                return(Conflict(input));
            }

            var imageResponse = await _imageUploader.DataLoaderAsync(file, "userProfile");

            if (!imageResponse.IsSuccess)
            {
                return(BadRequest(imageResponse.Message));
            }

            var student = new Data.Student
            {
                Name            = input.Name,
                Bio             = input.Bio,
                ProfileImageUrl = imageResponse.Data,
                Username        = input.Username,
                EmailAddress    = input.EmailAddress,
            };

            _db.Students.Add(student);
            await _db.SaveChangesAsync();

            var result = student.MapStudentResponse();

            return(CreatedAtAction(nameof(GetStudent), new { username = result.Username }, result));
        }