Esempio n. 1
0
        public static string EntityErrorsToString(EntityError[] EntityErrors)
        {
            string entityErrors = string.Empty;

            foreach (var error in EntityErrors)
            {
                entityErrors += error.ErrorMessage + "; ";
            }

            if (!String.IsNullOrEmpty(entityErrors))
            {
                entityErrors = entityErrors.Remove(entityErrors.Length - 2);
            }

            return entityErrors;
        }
Esempio n. 2
0
        public IResult Insert(User user, Guid userId)
        {
            string connectionString = ConfigurationManager.ConnectionStrings["default"].ConnectionString;

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                connection.Open();
                using (SqlTransaction transaction = connection.BeginTransaction(IsolationLevel.ReadCommitted))
                {
                    try
                    {
                        Guid? id;

                        if (user.Id == null)
                        {
                            id = Guid.NewGuid();
                        }
                        else
                        {
                            // jhj - id = user.Id;
                            id = userId;
                        }

                        user.UtcCreatedDate = DateTime.Now;

                        UserDb.Insert(transaction,
                                      id,
                                      user.Username,
                                      user.PasswordHash,
                                      user.PasswordHint,
                                      user.Language_Code,
                                      user.Description,
                                      user.UserGroup_Id,
                                      (int)user.StatusId,
                                      user.CreatedUserId,
                                      user.UtcCreatedDate);

                        PersonDb.Insert(transaction,
                            ref id,
                            user.FirstName,
                            user.Surname,
                            user.EmailAddress,
                            user.PhoneHome,
                            user.PhoneMobile,
                            user.PhoneOffice,
                            user.Fax,
                            user.Description,
                            user.Gender,
                            user.Disability,
                            user.DisabilityNote,
                            user.PreferredName,
                            (int) ActiveStatus.Active,
                            userId);

                        transaction.Commit();
                        return new InsertResult();
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();

                        var entityError = new EntityError("UserBll", "Insert", ex.Message);
                        return new InsertResult(entityError);
                    }
                }
            }
        }