Ejemplo n.º 1
0
        public static User Update(User user)
        {
            bool isNew = user.IsNew;

            UserMapper.Instance.Update(user);

            if (user.BrandsLoaded)
            {
                if (!isNew)
                {
                    UserBrandMapper.Instance.DeleteUserBrands(user.UserId);
                }

                if (user.UserRole != Shared.UserRole.SuperAdministrator)
                {
                    foreach (Brand brand in user.Brands)
                    {
                        UserBrand ub = UserBrand.New();
                        ub.UserId  = user.UserId.GetValueOrDefault();
                        ub.BrandId = brand.BrandId.GetValueOrDefault();
                        UserBrand.Update(ub);
                    }
                }
            }

            return(user);
        }
Ejemplo n.º 2
0
        protected override object ReadRow(IRowReader reader)
        {
            UserBrand userBrand = UserBrand.New();

            // Table Fields
            userBrand.UserBrandId = reader.GetInt32("UserBrandId");
            userBrand.UserId      = reader.GetInt32("UserId");
            userBrand.BrandId     = reader.GetInt32("BrandId");


            userBrand.IsDirty = false;
            userBrand.ChangedProperties.Clear();

            return(userBrand);
        }
Ejemplo n.º 3
0
        public virtual UserBrand Update(UserBrand userBrand)
        {
            if (!userBrand.IsDirty || userBrand.IsNull)
            {
                // Nothing to do - no point hammering the database unnecessarily
                return(userBrand);
            }

            IDbCommand command = CreateCommand();

            if (userBrand.IsNew)
            {
                // Adding
                command.CommandText = "INSERT INTO [UserBrand] ([UserId], [BrandId]) VALUES (@userId, @brandId) ; SELECT @@identity AS NewId;";
            }
            else
            {
                // Updating
                command.CommandText = "UPDATE [UserBrand] SET [UserId] = @userId, [BrandId] = @brandId WHERE UserBrandId = @userBrandId";
            }

            command.Parameters.Add(CreateParameter("@userId", userBrand.UserId));
            command.Parameters.Add(CreateParameter("@brandId", userBrand.BrandId));

            if (userBrand.IsNew)
            {
                userBrand.UserBrandId = Convert.ToInt32(ExecScalar(command));
            }
            else
            {
                command.Parameters.Add(CreateParameter("@userBrandId", userBrand.UserBrandId));
                ExecuteCommand(command);
            }

            userBrand.IsDirty = false;
            userBrand.ChangedProperties.Clear();

            return(userBrand);
        }
Ejemplo n.º 4
0
        public static UserBrand FindOne(UserBrandFinder finder)
        {
            UserBrand UserBrand = UserBrandMapper.Instance.FindOne(finder);

            return(UserBrand ?? Empty);
        }
Ejemplo n.º 5
0
 public static UserBrand Update(UserBrand userBrand)
 {
     return(UserBrandMapper.Instance.Update(userBrand));
 }
Ejemplo n.º 6
0
        public static UserBrand Get(Nullable <Int32> UserBrandId)
        {
            UserBrand UserBrand = UserBrandMapper.Instance.Get(UserBrandId);

            return(UserBrand ?? Empty);
        }