コード例 #1
0
        public async Task <PasswordDetailViewModel> EditPasswordAsync(PasswordEditInputModel par_InputModel)
        {
            bool bPasswordNonDuplicata = await DescrizioneDuplicataAsync(par_InputModel.Descrizione, par_InputModel.Id);

            if (bPasswordNonDuplicata == false)
            {
                throw new PasswordDescrizioneDuplicataException(par_InputModel.Descrizione, new Exception("errore nella creazione della password"));
            }
            string sFilePath = null;

            if (par_InputModel.FilePassword != null)
            {
                try
                {
                    sFilePath = await par_ImagePersister.SavePasswordImageAsync(par_InputModel.Id, par_InputModel.FilePassword);
                }
                catch (System.Exception exc)
                {
                    throw new PasswordImageInvalidException(par_InputModel.Id, exc);
                }
            }
            int var_NumRigheUpd = await db.CommandAsync($@"UPDATE Passwords 
                                                        SET PathFile=COALESCE({sFilePath}, PathFile), 
                                                        Password={par_InputModel.Password}, 
                                                        Descrizione={par_InputModel.Descrizione}, 
                                                        DataInserimento={par_InputModel.DataInserimento}, 
                                                        FkUtente={par_InputModel.FkUtente}, 
                                                        Sito={par_InputModel.Sito}, 
                                                        Tipo={par_InputModel.Tipo} 
                                                        WHERE Id={par_InputModel.Id} AND RowVersion={par_InputModel.RowVersion}");

            if (var_NumRigheUpd == 0)
            {
                int var_RecordTrovato = await db.QueryScalarAsync <int>($"SELECT COUNT(*) FROM Passwords WHERE Id={par_InputModel.Id}");

                if (var_RecordTrovato > 0)
                {
                    throw new DBConcurrencyException("Non e' possibile effettuare l'update perche un altro utente ha effettuato delle modifiche.");
                }
                else
                {
                    throw new PasswordNotFoundException(par_InputModel.Id);
                }
            }
            PasswordDetailViewModel var_Password = await GetPasswordAsync(par_InputModel.Id.ToString());

            return(var_Password);
        }
コード例 #2
0
ファイル: AdoNetUserStore.cs プロジェクト: k0say/MyCourse-1
        public async Task <IdentityResult> CreateAsync(ApplicationUser user, CancellationToken token)
        {
            int affectedRows = await db.CommandAsync($"INSERT INTO AspNetUsers (Id, UserName, NormalizedUserName, Email, NormalizedEmail, EmailConfirmed, PasswordHash, SecurityStamp, ConcurrencyStamp, PhoneNumber, PhoneNumberConfirmed, TwoFactorEnabled, LockoutEnd, LockoutEnabled, AccessFailedCount, FullName) VALUES ({user.Id}, {user.UserName}, {user.NormalizedUserName}, {user.Email}, {user.NormalizedEmail}, {user.EmailConfirmed}, {user.PasswordHash}, {user.SecurityStamp}, {user.ConcurrencyStamp}, {user.PhoneNumber}, {user.PhoneNumberConfirmed}, {user.TwoFactorEnabled}, {user.LockoutEnd}, {user.LockoutEnabled}, {user.AccessFailedCount}, {user.FullName})", token);

            if (affectedRows > 0)
            {
                return(IdentityResult.Success);
            }
            var error = new IdentityError {
                Description = "Could not insert user"
            };

            return(IdentityResult.Failed(error));
        }
コード例 #3
0
        public async Task DeleteLessonAsync(LessonDeleteInputModel inputModel)
        {
            int affectedRows = await db.CommandAsync($"DELETE FROM Lessons WHERE Id={inputModel.Id}");

            if (affectedRows == 0)
            {
                throw new LessonNotFoundException(inputModel.Id);
            }
        }
コード例 #4
0
        public async Task <CourseDetailViewModel> EditCourseAsync(CourseEditInputModel inputModel)
        {
            try
            {
                string imagePath = null;
                if (inputModel.Image != null)
                {
                    imagePath = await imagePersister.SaveCourseImageAsync(inputModel.Id, inputModel.Image);
                }
                int affectedRows = await db.CommandAsync($"UPDATE Courses SET ImagePath=COALESCE({imagePath}, ImagePath), Title={inputModel.Title}, Description={inputModel.Description}, Email={inputModel.Email}, CurrentPrice_Currency={inputModel.CurrentPrice.Currency.ToString()}, CurrentPrice_Amount={inputModel.CurrentPrice.Amount}, FullPrice_Currency={inputModel.FullPrice.Currency.ToString()}, FullPrice_Amount={inputModel.FullPrice.Amount} WHERE Id={inputModel.Id} AND Status<>{nameof(CourseStatus.Deleted)} AND RowVersion={inputModel.RowVersion}");

                if (affectedRows == 0)
                {
                    bool courseExists = await db.QueryScalarAsync <bool>($"SELECT COUNT(*) FROM Courses WHERE Id={inputModel.Id} AND Status<>{nameof(CourseStatus.Deleted)}");

                    if (courseExists)
                    {
                        throw new OptimisticConcurrencyException();
                    }
                    else
                    {
                        throw new CourseNotFoundException(inputModel.Id);
                    }
                }
            }
            catch (ConstraintViolationException exc)
            {
                throw new CourseTitleUnavailableException(inputModel.Title, exc);
            }
            catch (ImagePersistenceException exc)
            {
                throw new CourseImageInvalidException(inputModel.Id, exc);
            }

            CourseDetailViewModel course = await GetCourseAsync(inputModel.Id);

            return(course);
        }