Esempio n. 1
0
        public static Company Update(Company company)
        {
            if (company.BrandListLoaded)
            {
                JoinableList jList = new JoinableList();
                company.BrandList.ForEach(b => jList.Add(b.Name));
                company.Brands = jList.ToString();
            }

            CompanyMapper.Instance.Update(company);

            if (company.BrandListLoaded)
            {
                CompanyBrandMapper.Instance.DeleteBrands(company.CompanyId);

                foreach (Brand brand in company.BrandList)
                {
                    CompanyBrand cb = CompanyBrand.New();
                    cb.CompanyId = company.CompanyId.GetValueOrDefault();
                    cb.BrandId   = brand.BrandId.GetValueOrDefault();
                    CompanyBrand.Update(cb);
                }
            }

            return(company);
        }
Esempio n. 2
0
        protected override object ReadRow(IRowReader reader)
        {
            CompanyBrand companyBrand = CompanyBrand.New();

            // Table Fields
            companyBrand.CompanyBrandId = reader.GetInt32("CompanyBrandId");
            companyBrand.CompanyId      = reader.GetInt32("CompanyId");
            companyBrand.BrandId        = reader.GetInt32("BrandId");


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

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

            IDbCommand command = CreateCommand();

            if (companyBrand.IsNew)
            {
                // Adding
                command.CommandText = "INSERT INTO [CompanyBrand] ([CompanyId], [BrandId]) VALUES (@companyId, @brandId) ; SELECT @@identity AS NewId;";
            }
            else
            {
                // Updating
                command.CommandText = "UPDATE [CompanyBrand] SET [CompanyId] = @companyId, [BrandId] = @brandId WHERE CompanyBrandId = @companyBrandId";
            }

            command.Parameters.Add(CreateParameter("@companyId", companyBrand.CompanyId));
            command.Parameters.Add(CreateParameter("@brandId", companyBrand.BrandId));

            if (companyBrand.IsNew)
            {
                companyBrand.CompanyBrandId = Convert.ToInt32(ExecScalar(command));
            }
            else
            {
                command.Parameters.Add(CreateParameter("@companyBrandId", companyBrand.CompanyBrandId));
                ExecuteCommand(command);
            }

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

            return(companyBrand);
        }
Esempio n. 4
0
        public static CompanyBrand FindOne(CompanyBrandFinder finder)
        {
            CompanyBrand CompanyBrand = CompanyBrandMapper.Instance.FindOne(finder);

            return(CompanyBrand ?? Empty);
        }
Esempio n. 5
0
 public static CompanyBrand Update(CompanyBrand companyBrand)
 {
     return(CompanyBrandMapper.Instance.Update(companyBrand));
 }
Esempio n. 6
0
        public static CompanyBrand Get(Nullable <Int32> CompanyBrandId)
        {
            CompanyBrand CompanyBrand = CompanyBrandMapper.Instance.Get(CompanyBrandId);

            return(CompanyBrand ?? Empty);
        }