示例#1
0
        public static BusinessObjectActionReport <UniqueUserActionStatus> Update(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.UpdateUniqueUser(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 updated 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 updated at the database because the validation failed. Report: "
                                    + actionReport.ValidationResult.ToString(CommonTools.TextFormat.ASCII));
            }

            return(actionReport);
        }