Exemplo n.º 1
0
        public static BusinessObjectActionReport <UniqueUserActionStatus> Delete(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.DeleteUniqueUser(user.UserID);
                    if (affectedRows == 0)
                    {
                        actionReport.Status = UniqueUserActionStatus.NoRecordRowAffected;
                        LogManager.LogEvent(ApplicationLocation.DataAccess, EventType.Error
                                            , "User " + user.UserID.ToString() + " was not deleted 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 deleted at the database because the validation failed. Report: "
                                    + actionReport.ValidationResult.ToString(CommonTools.TextFormat.ASCII));
            }

            return(actionReport);
        }