Exemple #1
0
        /// <summary>
        /// Método responsável por manipular o comando de adicionar uma marca
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        public IResponse handle(CommandAddBrand command)
        {
            // validação rapida
            command.Validate();
            if (command.Invalid)
            {
                return(new ResponseError <CommandAddBrand>(
                           errorCode: "400",
                           description: "Não foi possível prosseguir com a solicitação",
                           data: command.Notifications
                           ));
            }

            // criar a entidade de marcas
            var brand = new CatalogBrand(brand: command.Brand);

            // faz a persistencia dos dados no banco de dados e retorna false caso apresentar algum erro
            if (!_repository.CreateBrandAsync(brand: brand))
            {
                return(new ResponseError <CommandAddBrand>(
                           errorCode: "400",
                           description: "Não foi possível prosseguir com a solicitação, pois foi apresentado um erro sistemico",
                           data: null
                           ));
            }

            // retorna sucesso na operação para adicionar um item no estoque de produto
            //return new ResponseOk<CatalogBrand>(brand);
            return(new ResponseOk <CatalogBrand>(brand));
        }
Exemple #2
0
            public Yield(CatalogContext dbContext)
            {
                var brands = dbContext.CatalogBrands.Where(brand => Markers.AllBrands.Contains(brand.Brand)).ToArray();

                Azure        = brands.First(brand => brand.Brand == Markers.AzureName);
                DotNet       = brands.First(brand => brand.Brand == Markers.DotNetName);
                VisualStudio = brands.First(brand => brand.Brand == Markers.VisualStudioName);
                SqlServer    = brands.First(brand => brand.Brand == Markers.SqlServerName);
                Roslyn       = brands.First(brand => brand.Brand == Markers.RoslynName);
            }
        public void Delete(CatalogBrand productcompany)
        {
            string json        = JsonConvert.SerializeObject(productcompany, Formatting.Indented);
            var    buffer      = System.Text.Encoding.UTF8.GetBytes(json);
            var    byteContent = new ByteArrayContent(buffer);

            byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
            var stringContent = new StringContent(JsonConvert.SerializeObject(productcompany), Encoding.UTF8, "application/json");
            var httpResponce  = _httpClient.PostAsync("ProductCompany/Delete", byteContent);
        }
        public ProductCompanyViewModel()
        {
            var Scope = Startup.Instance.provider.CreateScope();


            _productCompany           = new CatalogBrand();
            _repositoryProductCompany = Scope.ServiceProvider.GetRequiredService <IProductCompanyService>();
            ProductCompanies          = _repositoryProductCompany.GetAllProductCompanies();
            WireCommands();
        }
 static IEnumerable <CatalogBrand> GetPreconfiguredCatalogBrands()
 {
     return(new List <CatalogBrand>()
     {
         CatalogBrand.Create("Rolleiflex"),
         CatalogBrand.Create("Hasselblad"),
         CatalogBrand.Create("Mamiya"),
         CatalogBrand.Create("Fuji")
     });
 }
Exemple #6
0
        public IActionResult ProductCompanyPost([FromBody] CatalogBrand referrer)
        {
            if (referrer == null)
            {
                return(BadRequest());
            }

            var identifier = _productcompanyService.Insert(referrer);


            return(Ok());
        }
Exemple #7
0
        public IActionResult Delete([FromBody] CatalogBrand productcompany)
        {
            if (productcompany == null)
            {
                return(BadRequest());
            }

            _productcompanyService.Delete(productcompany);


            return(Ok());
        }
Exemple #8
0
        public ActionResult Edit(CatalogBrand entity)
        {
            var dao   = new CatalogDao();
            var check = dao.UpdateCatalogBrand(entity);

            if (check == 1)
            {
                TempData["Message"] = "Cập nhật thành công";
                return(RedirectToAction("index"));
            }
            ModelState.AddModelError("", "Cập nhật thất bại");
            return(View());
        }
Exemple #9
0
 public string Insert(CatalogBrand productcompany)
 {
     _unitOfWork.GetRepository <CatalogBrand>().Add(productcompany);
     try
     {
         _unitOfWork.SaveChanges();
     }
     catch (Exception ex)
     {
         string msg = ex.Message;
     }
     return(productcompany.Identifier);
 }
Exemple #10
0
        public void Delete(CatalogBrand productcompany)
        {
            try
            {
                _unitOfWork.GetRepository <CatalogBrand>().Delete(productcompany.Id);


                _unitOfWork.SaveChanges();
            }
            catch (Exception ex)
            {
                string msg = ex.Message;
            }
        }
Exemple #11
0
 public int UpdateCatalogBrand(CatalogBrand entity)
 {
     try
     {
         var brand = db.CatalogBrands.Find(entity.id);
         brand.updatedAt  = DateTime.Now;
         brand.brand      = entity.brand;
         brand.pictureurl = entity.pictureurl;
         db.SaveChanges();
         return(1);
     }
     catch (Exception)
     {
         return(0);
     }
 }
Exemple #12
0
        /// <summary>
        /// Cria uma nova marca no repositorio
        /// </summary>
        /// <param name="brand"></param>
        /// <returns></returns>
        public bool CreateBrandAsync(CatalogBrand brand)
        {
            var parameterProc = new Dictionary <string, object>();

            parameterProc.Add("@brand", brand.Brand);

            try
            {
                _database.GetResponse("pr_create_brand", parameterProc);
                return(true);
            }
            catch (Exception e)
            {
                Console.Error.Write($"Erro: {e}");
                return(false);
            }
        }
        public IList <CatalogBrandModel> GetCatalogBrands()
        {
            _catalogBrands = new List <CatalogBrandModel>();
            var provider  = new SqlServerProvider(ConnectionString);
            var dataTable = provider.GetCatalogBrands();

            foreach (DataRow item in dataTable.Rows)
            {
                var record = new CatalogBrand
                {
                    Id    = (int)item["Id"],
                    Brand = item["Name"] as String,
                };
                _catalogBrands.Add(new CatalogBrandModel(record));
            }
            return(_catalogBrands);
        }
        static void Main(string[] args)
        {
            using (var context = new ApplicationContext())
            {
                var buyerRepository = new BuyerRepository(context);


                context.Database.Migrate();
                var paymentMethod = new PaymentMethod()
                {
                    CardId = "testCard"
                };

                var buyer = new Buyer(paymentMethod);

                var catalogueBrand = new CatalogBrand("Brand");
                var catalogType    = new CatalogType();

                var catalogueItem = new CatalogItem("Beautiful Item", 100, catalogueBrand, catalogType);


                var basket = new Basket(buyer);


                var address = new Address("street", "city", "state", "country", "zipcode");

                var order = new Order(buyer, address, basket);

                buyerRepository.SaveBuyer(buyer);
                context.Basket.Add(basket);
                context.CatalogItem.Add(catalogueItem);
                basket.AddItem(catalogueItem, 1);
                context.Order.Add(order);
                context.CatalogBrand.Add(catalogueBrand);
                context.CatalogType.Add(catalogType);
                context.SaveChanges();


                var a = context.Basket.Where(x => x.Buyer.PaymentMethods.Any(y => y.CardId == "testCard"));
                var b = context.Buyer.Where(x => x.Basket.Items.Any(y => y.Quantity == 1));
            }
        }
Exemple #15
0
 // catalog brand
 public int AddNewBrand(CatalogBrand entity)
 {
     try
     {
         entity.createdAt = DateTime.Now;
         entity.updatedAt = DateTime.Now;
         var sl = db.CatalogBrands.Where(x => x.brand == entity.brand).Count();
         if (sl > 0)
         {
             return(0);
         }
         db.CatalogBrands.Add(entity);
         db.SaveChanges();
         return(1);
     }
     catch (Exception)
     {
         return(-1);
     }
 }
Exemple #16
0
 public int SaveBrand(BrandDTO model)
 {
     if (model.id == 0)
     {
         var data = _context.CatalogBrands.Count(x => x.brand == model.brand);
         if (data > 0)
         {
             return(-1);
         }
         var brand = new CatalogBrand();
         brand.brand      = model.brand;
         brand.pictureurl = model.pictureurl;
         _context.CatalogBrands.Add(brand);
         try
         {
             _context.SaveChanges();
         }
         catch (Exception)
         {
             return(0);
         }
     }
     else
     {
         var brand = _context.CatalogBrands.Find(model.id);
         brand.brand      = model.brand;
         brand.pictureurl = model.pictureurl;
         try
         {
             _context.SaveChanges();
         }
         catch (Exception)
         {
             return(0);
         }
     }
     return(1);
 }
Exemple #17
0
 public ActionResult AddNewBrand(CatalogBrand entity)
 {
     if (ModelState.IsValid)
     {
         var catalogDao = new CatalogDao();
         try
         {
             int check = catalogDao.AddNewBrand(entity);
             if (check == 1)
             {
                 TempData["Message"] = "Thêm thương hiệu thành công";
                 return(RedirectToAction("index"));
             }
             ModelState.AddModelError("", "Đã tồn tại tên thương hiệu");
             return(View("AddNewBrand"));
         }
         catch (Exception)
         {
             ModelState.AddModelError("", "Lỗi!");
             return(View("AddNewBrand"));
         }
     }
     return(View("AddNewBrand"));
 }
Exemple #18
0
 public CatalogBrandModel(CatalogBrand source)
 {
     Id   = source.Id;
     Name = source.Brand;
 }
        public void DeleteProductCompany()
        {
            CatalogBrand p = CurrentProductCompany;

            _repositoryProductCompany.Delete(p);
        }
        public async Task <IList <CatalogItem> > GetItemsAsync(CatalogType catalogType, CatalogBrand catalogBrand, string query)
        {
            int catalogTypeId  = catalogType == null ? 0 : catalogType.Id;
            int catalogBrandId = catalogBrand == null ? 0 : catalogBrand.Id;

            string path = $"api/v1/catalog/items/type/{catalogTypeId}/brand/{catalogBrandId}";

            using (var cli = new WebApiClient(BaseAddressUri))
            {
                var pagination = await cli.GetAsync <PaginatedItems <CatalogItem> >(path, QueryParam.Create("pageSize", 100));

                var items = pagination.Data;

                if (!String.IsNullOrEmpty(query))
                {
                    items = items.Where(r => $"{r.Name}".ToUpper().Contains(query.ToUpper()));
                }

                await Populate(items);

                return(items.ToList());
            }
        }
Exemple #21
0
 public async Task <IList <CatalogItem> > GetItemsAsync(CatalogType selectedCatalogType, CatalogBrand selectedCatalogBrand, string query)
 {
     try
     {
         return(await Current.GetItemsAsync(selectedCatalogType, selectedCatalogBrand, query));
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine(ex.Message);
         return(new List <CatalogItem>());
     }
 }
 public void UnAssignCatalog(int brandId, int catalogId)
 {
     CatalogBrand = Db.CatalogBrand.FirstOrDefault(c => c.BrandId == brandId && c.CatalogId == catalogId);
     Db.CatalogBrand.Remove(CatalogBrand);
 }
        public async Task <IList <CatalogItem> > GetItemsAsync(CatalogType catalogType, CatalogBrand catalogBrand, string query)
        {
            await Task.FromResult(true);

            using (var db = new LocalCatalogDb())
            {
                IEnumerable <CatalogItem> items = db.CatalogItems;

                if (!String.IsNullOrEmpty(query))
                {
                    items = items.Where(r => $"{r.Name}".ToUpper().Contains(query.ToUpper()));
                }

                if (catalogType != null && catalogType.Id > 0)
                {
                    items = items.Where(r => r.CatalogTypeId == catalogType.Id);
                }

                if (catalogBrand != null && catalogBrand.Id > 0)
                {
                    items = items.Where(r => r.CatalogBrandId == catalogBrand.Id);
                }

                return(Populate(db, items.ToArray().OrderBy(r => r.Name)).ToList());
            }
        }
 private void MockGetByIdAsync(int catalogTypeId, int catalogBrandId, CatalogType catalogType, CatalogBrand catalogBrand)
 {
     _mockCatalogTypeRepository
     .Setup(x => x.GetByIdAsync(catalogTypeId))
     .ReturnsAsync(catalogType);
     _mockCatalogBrandRepository
     .Setup(x => x.GetByIdAsync(catalogBrandId))
     .ReturnsAsync(catalogBrand);
 }
 public void AssignCatalog(BrandAssignModel model)
 {
     CatalogBrand = _mapper.Map <CatalogBrand>(model);
     Db.CatalogBrand.Add(CatalogBrand);
 }