Ejemplo n.º 1
0
        public int CreateEntity(BlogUser blogUserToCreate)
        {
            using (var cmd = UnitOfWork.CreateCommand())
            {
                try
                {
                    cmd.CommandText = "CreateBlogUser";
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add(new SqlParameter("@UserName", SqlDbType.VarChar, 50)
                    {
                        Value = blogUserToCreate.UserName
                    });
                    cmd.Parameters.Add(new SqlParameter("@UserPassword", SqlDbType.VarChar, 50)
                    {
                        Value = blogUserToCreate.UserPassword
                    });
                    var outPutParameter = new SqlParameter("@CreatedUserId", SqlDbType.Int, 50,
                                                           ParameterDirection.InputOutput, false, 0, 0, "@CreatedUserId", DataRowVersion.Original, null);
                    outPutParameter.Value = ParameterDirection.InputOutput;
                    cmd.Parameters.Add(outPutParameter);

                    cmd.ExecuteNonQuery();
                    int createdUserId = Convert.ToInt32(outPutParameter.Value);
                    _blogUserBuilder.SetBlogUserId(blogUserToCreate, createdUserId);

                    return(createdUserId);
                }
                catch (SqlException ex)
                {
                    throw new ApplicationException(ex.Message, ex);
                }
            }
        }
Ejemplo n.º 2
0
        public AnswerStatus UpdateUser(BlogUserDto userDTO)
        {
            using (var uow = _unitOfWorkFactory.Create())
            {
                try
                {
                    var userToUpdate = _blogUserBuilder.CreateBlogUser(userDTO.UserName, userDTO.UserPassword);
                    _blogUserBuilder.SetBlogUserId(userToUpdate, userDTO.Id);
                    var userRepository = _repositoryFactory.CreateUserRepository(uow);
                    userRepository.UpdateEntity(userToUpdate);

                    uow.SaveChanges();

                    return(AnswerStatus.Successfull);
                }
                catch (Exception exc)
                {
                    _logger.Log(exc.ToString());

                    return(AnswerStatus.Failed);
                }
            }
        }