Ejemplo n.º 1
0
        /// <summary>
        /// Submits a new brand for persistence.
        /// </summary>
        /// <param name="newBrand">New brand to save.</param>
        public void Insert(BrandDTO newBrand)
        {
            // Throws an an exception for a null dto
            if (newBrand == null)
                throw new ArgumentNullException("newBrand",
                    "newBrand does not accept a null dot as an argument.");

            using (var context = new openTillEntities())
            {
                // Throws an exception if a brand with the given name already exists
                if (context.Brands.SingleOrDefault(b => b.Name == newBrand.Name) != null)
                    throw new InvalidOperationException("A brand with the given brand name already exists.");

                context.Brands.Add(Mapper.Map<Brand>(newBrand));
                context.SaveChanges();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Deletes a brand.
        /// </summary>
        /// <param name="brandDel">Brand to delete</param>
        public void Delete(BrandDTO brandDel)
        {
            // Throws an an exception for a null dto
            if (brandDel == null)
                throw new ArgumentNullException("brandDel",
                    "brandDel does not accept a null dot as an argument.");

            using (var context = new openTillEntities())
            {
                var brand = context.Brands.SingleOrDefault(b => b.Id == brandDel.Id);

                // Throws an exception if no matching entry is found
                if (brand == null)
                    throw new InvalidOperationException("No entry matching the given brand was found.");

                context.Brands.Remove(brand);
                context.SaveChanges();
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Updates an existing brand.
        /// </summary>
        /// <param name="brandUpdate">Brand to update</param>
        public void Update(BrandDTO brandUpdate)
        {
            // Throws an an exception for a null dto
            if (brandUpdate == null)
                throw new ArgumentNullException("brandUpdate",
                    "brandUpdate does not accept a null dot as an argument.");

            using (var context = new openTillEntities())
            {
                var brand = context.Brands.SingleOrDefault(b => b.Id == brandUpdate.Id);

                // Throws an exception if the given brand doesn't exist
                if (brand == null)
                    throw new InvalidOperationException("No entry matching the given brand was found.");

                // Throws an exception if a brand with the given name already exists
                if (context.Brands.SingleOrDefault(b => b.Name == brandUpdate.Name) != null)
                    throw new InvalidOperationException("A brand with the given brand name already exists.");

                // Update existing brand
                brand.Name = brandUpdate.Name;

                context.SaveChanges();
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Method calls on repository to update an existing Brand in the database.
 /// </summary>
 /// <param name="givenBrand">Brand Data Transfer Object to the updated in the database.</param>
 public void Update(BrandDTO givenBrand)
 {
     var brandToUpdate = Mapper.Map<BrandDTO>(givenBrand);
     _brandRepository.Update(brandToUpdate);
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Method calls on repository to insert a new brand into the database.
 /// </summary>
 /// <param name="givenBrand">Brand Data Transfer Object to be inserted into the database.</param>
 public void Insert(BrandDTO givenBrand)
 {
     var brandToCreate = Mapper.Map<BrandDTO>(givenBrand);
     _brandRepository.Insert(brandToCreate);
 }
Ejemplo n.º 6
0
 public ObservableBrand(BrandDTO dto)
 {
     Id = dto.Id;
     BrandName = dto.Name;
 }