コード例 #1
0
ファイル: UniqueUserManager.cs プロジェクト: tm011064/Luputa
        public static BusinessObjectActionReport <UniqueUserActionStatus> Create(UniqueUser user)
        {
            BusinessObjectActionReport <UniqueUserActionStatus> actionReport = new BusinessObjectActionReport <UniqueUserActionStatus>(UniqueUserActionStatus.Success);

            actionReport.ValidationResult = BusinessObjectManager.Validate(user);
            if (actionReport.ValidationResult.IsValid)
            {
                try
                {
                    UsersDataContext dc = Configuration.GetUsersDataContext();

                    int affectedRows = dc.InsertUniqueUser(user.UserID, user.AccountStatus, user.Timezone, user.Firstname
                                                           , user.Lastname, user.DateOfBirth, user.City, user.IsNewletterSubscriber);

                    if (affectedRows == 0)
                    {
                        actionReport.Status = UniqueUserActionStatus.NoRecordRowAffected;
                        LogManager.LogEvent(ApplicationLocation.DataAccess, EventType.Error, "User " + user.UserID.ToString() + " was not inserted at the database.");
                    }
                }
                catch (SqlException ex)
                {
                    actionReport.Status = UniqueUserActionStatus.SqlException;
                    LogManager.LogException(ApplicationLocation.DataAccess, ex);
                }
                catch (Exception ex)
                {
                    actionReport.Status = UniqueUserActionStatus.UnknownError;
                    LogManager.LogException(ApplicationLocation.DataAccess, ex);
                }
                finally
                {
                }
            }
            else
            {
                actionReport.Status = UniqueUserActionStatus.ValidationFailed;
                LogManager.LogEvent(ApplicationLocation.DataAccess, EventType.Warning, "User " + user.UserID.ToString() + " was not inserted at the database because the validation failed. Report: "
                                    + actionReport.ValidationResult.ToString(CommonTools.TextFormat.ASCII));
            }

            return(actionReport);
        }