public async Task <CourseDetailViewModel> CreateCourseAsync(CourseCreateInputModel inputModel)
        {
            string title = inputModel.Title;
            string author;
            string authorId;

            try
            {
                author   = httpContextAccessor.HttpContext.User.FindFirst("FullName").Value;
                authorId = httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value;
            }
            catch (NullReferenceException)
            {
                throw new UserUnknownException();
            }

            try
            {
                int courseId = await db.QueryScalarAsync <int>($@"INSERT INTO Courses (Title, Author, AuthorId, ImagePath, Rating, CurrentPrice_Currency, CurrentPrice_Amount, FullPrice_Currency, FullPrice_Amount, Status) VALUES ({title}, {author}, {authorId}, '/Courses/default.png', 0, 'EUR', 0, 'EUR', 0, {nameof(CourseStatus.Draft)});
                                                 SELECT last_insert_rowid();");

                CourseDetailViewModel course = await GetCourseAsync(courseId);

                return(course);
            }
            catch (ConstraintViolationException exc)
            {
                throw new CourseTitleUnavailableException(inputModel.Title, exc);
            }
        }
Esempio n. 2
0
        public async Task <LessonDetailViewModel> CreateLessonAsync(LessonCreateInputModel inputModel)
        {
            int lessonId = await db.QueryScalarAsync <int>($@"INSERT INTO Lessons (Title, CourseId, Duration) VALUES ({inputModel.Title}, {inputModel.CourseId}, '00:00:00');
                                                 SELECT last_insert_rowid();");

            LessonDetailViewModel lesson = await GetLessonAsync(lessonId);

            return(lesson);
        }
Esempio n. 3
0
        public async Task <CourseDetailViewModel> CreateCourseAsync(CourseCreateInputModel inputModel)
        {
            string title  = inputModel.Title;
            string author = "Mario Rossi";

            try
            {
                int courseId = await db.QueryScalarAsync <int>($@"INSERT INTO Courses (Title, Author, ImagePath, Rating, CurrentPrice_Currency, CurrentPrice_Amount, FullPrice_Currency, FullPrice_Amount, Status) VALUES ({title}, {author}, '/Courses/default.png', 0, 'EUR', 0, 'EUR', 0, {nameof(CourseStatus.Draft)});
                                                 SELECT last_insert_rowid();");

                CourseDetailViewModel course = await GetCourseAsync(courseId);

                return(course);
            }
            catch (ConstraintViolationException exc)
            {
                throw new CourseTitleUnavailableException(inputModel.Title, exc);
            }
        }
Esempio n. 4
0
        public async Task <PasswordDetailViewModel> CreatePasswordAsync(PasswordCreateInputModel par_InputModel)
        {
            string sDescrizione     = par_InputModel.Descrizione;
            string sDataInserimento = Convert.ToString(DateTime.Now);

            bool bPasswordNonDuplicata = await DescrizioneDuplicataAsync(sDescrizione, 0);

            if (bPasswordNonDuplicata == true)
            {
                PasswordDetailViewModel var_Password;
                string sId = await db.QueryScalarAsync <string>($@"INSERT INTO Passwords (Descrizione, DataInserimento) VALUES ({sDescrizione}, {sDataInserimento});
                                                     SELECT last_insert_rowid();");

                var_Password = await GetPasswordAsync(sId);

                return(var_Password);
            }
            else
            {
                throw new PasswordDescrizioneDuplicataException(sDescrizione, new Exception("errore nella creazione della password"));
            }
        }
Esempio n. 5
0
 public Task <string> GetTokenAsync(ApplicationUser user, string loginProvider, string name, CancellationToken token)
 {
     return(db.QueryScalarAsync <string>($"SELECT Value FROM AspNetUserTokens WHERE UserId={user.Id} AND LoginProvider={loginProvider} AND Name={name}", token));
 }