public AddProduct()
        {
            InitializeComponent();
            CategoryDb categories = new CategoryDb();

            picker.ItemsSource = categories.GetCategories().ToList();
        }
Beispiel #2
0
        private static void AdaugaCategorii(AnabiContext context)
        {
            var categorii = new CategoryDb[]
            {
                new CategoryDb()
                {
                    ForEntity = "bun", Code = "Bunuri Mobile", Description = "Bunuri care pot fi ridicate"
                },
                new CategoryDb()
                {
                    ForEntity = "bun", Code = "Bunuri Imobile", Description = "Bunuri care nu pot fi ridicate"
                },
                new CategoryDb()
                {
                    ForEntity = "bun", Code = "Bani", Description = "Bani"
                },
                new CategoryDb()
                {
                    ForEntity = "institutie", Code = "Instanta", Description = ""
                },
                new CategoryDb()
                {
                    ForEntity = "institutie", Code = "Parchet"
                }
            };

            context.Categorii.AddRange(categorii);
            context.SaveChanges();
        }
Beispiel #3
0
        // GET: Category
        public ActionResult Index()
        {
            string err        = string.Empty;
            var    categories = new CategoryDb().GetCategories(ref err);

            return(View(categories));
        }
 public void OnSaveClicked(object sender, EventArgs args)
 {
     categoryDb = new CategoryDb();
     productCategory.CategoryName = txtCateName.Text;
     categoryDb.EditAdmin(productCategory);
     Navigation.PushAsync(new ManageCategories());
 }
 public static CategoryAdd Map(this CategoryDb category)
 {
     return(new CategoryAdd
     {
         Id = category.Id,
         Name = category.Name
     });
 }
Beispiel #6
0
        public void OnSaveClicked(object sender, EventArgs args)
        {
            category              = new ProductCategory();
            categoryDb            = new CategoryDb();
            category.CategoryName = txtcategoryName.Text;
            categoryDb.AddCategory(category);

            Navigation.PushAsync(new ManageCategories());
        }
Beispiel #7
0
        public static void GetProductsInCategory(int id)
        {
            IEnumerable <Product> list = GoodsDb.GetProductsByCategoryId(id);

            foreach (var product in list)
            {
                Console.WriteLine("В категории {0} есть товар {1}", CategoryDb.GetCategoryById(id).Name, product.Title);
            }
        }
Beispiel #8
0
        public ManageCategories()
        {
            InitializeComponent();

            _database = new CategoryDb();

            var categories = _database.GetCategories();

            lstData.ItemsSource = categories;
        }
Beispiel #9
0
        // GET: Admin/Product
        public ActionResult Index(string searchString = "", int categoryID = 0)
        {
            var categories = new CategoryDb().GetCategories(ref err, 0);

            ViewBag.categoryID = new SelectList(categories, "ID", "Name");
            //viet code de lay products list.
            var products = new ProductDb().GetProducts(ref err, searchString, categoryID);

            return(View(products));
        }
Beispiel #10
0
        public void should_throw_exception_when_entity_not_found()
        {
            CategoryDb categoryDb = null;

            _categories.Setup(n => n.GetById(1)).Returns(categoryDb);

            _sut.Invoking(n => n.Delete(1))
            .Should()
            .Throw <ArgumentNullException>()
            .WithMessage(string.Format(ApiResponses.CategoryWithGivenIdNotFound, 1));
        }
        public void should_add_category()
        {
            CategoryAdd category       = new() { Name = "Category test name" };
            CategoryDb  mappedCategory = category.Map();

            _mapper.Setup(n => n.Map <CategoryDb>(category)).Returns(mappedCategory);

            _sut.Add(category);

            _categories.Verify(n => n.Insert(mappedCategory));
        }
        public void should_commit_db_changes()
        {
            CategoryAdd category       = new() { Name = "Category test name" };
            CategoryDb  mappedCategory = category.Map();

            _mapper.Setup(n => n.Map <CategoryDb>(category)).Returns(mappedCategory);

            _sut.Add(category);

            _categoriesUnitOfWork.Verify(n => n.Commit());
        }
Beispiel #13
0
        public async void OnDeleteClicked(object sender, EventArgs args)
        {
            categoryDb = new CategoryDb();
            bool accepted = await DisplayAlert("Confirm", "Are you Sure ?", "Yes", "No");

            if (accepted)
            {
                categoryDb.DeleteCategory(productCategory);
            }
            await Navigation.PushAsync(new ManageCategories());
        }
Beispiel #14
0
 public ActionResult Delete(int id, Category collection)
 {
     try
     {
         // TODO: Add delete logic here
         var result = new CategoryDb().DeleteCategoryByID(ref err, ref rows, collection);
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
Beispiel #15
0
 public ActionResult Edit(int id, Category collection)
 {
     try
     {
         // TODO: Add update logic here
         var result = new CategoryDb().InsertUpdateCategory(ref err, ref rows, collection);
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
 public ActionResult Create(Category collection)
 {
     try
     {
         // TODO: Add insert logic here
         var result = new CategoryDb().InserCategory(ref err, ref rows, collection);
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
        public async Task <int> Handle(AddCategory message, CancellationToken cancellationToken)
        {
            var newCategory = new CategoryDb();

            mapper.Map(message, newCategory);
            newCategory.UserCodeAdd = UserCode();

            context.Categories.Add(newCategory);

            await context.SaveChangesAsync();

            return(newCategory.Id);
        }
        public static Category MapToCategory(this CategoryDb category)
        {
            if (category is null)
            {
                return(null);
            }

            return(new Category {
                Id = category.Id,
                Name = category.Name,
                //Websites = category.Websites.ToList(),
            });
        }
        public void should_add_website_details_when_WebsiteIds_fulfilled()
        {
            CategoryAdd category = new() {
                Name        = "Category test name",
                WebsitesIds = new List <int> {
                    1, 3
                }
            };
            CategoryDb mappedCategory = category.Map();

            WebsiteDetailsDb[] websiteDetails = new WebsiteDetailsDb[] {
                new WebsiteDetailsDb {
                    id = 1, Url = "test url 1"
                },
                new WebsiteDetailsDb {
                    id = 3, Url = "test url 3"
                },
            };

            CategoryDb expectedResult = new()
            {
                Id       = 0,
                Name     = "Category test name",
                Websites = new List <WebsiteDetailsDb> {
                    new WebsiteDetailsDb {
                        id = 1, Url = "test url 1"
                    },
                    new WebsiteDetailsDb {
                        id = 3, Url = "test url 3"
                    }
                }
            };

            CategoryDb          insertedCategoryDb = null;
            Action <CategoryDb> insertCategory     = (cat) => { insertedCategoryDb = cat; };

            _mapper.Setup(n => n.Map <CategoryDb>(category)).Returns(mappedCategory);
            _websiteDetails.Setup(n => n.Get(
                                      n => category.WebsitesIds.Contains(n.id),
                                      It.IsAny <Func <IQueryable <WebsiteDetailsDb>, IOrderedQueryable <WebsiteDetailsDb> > >(),
                                      It.IsAny <string>())).Returns(websiteDetails);
            _categories.Setup(n => n.Insert(It.IsAny <CategoryDb>())).Callback(insertCategory);

            var result = _sut.Add(category);

            insertedCategoryDb.Should().BeEquivalentTo(expectedResult);
        }

        [Fact]
        // GET: Category
        public ActionResult Index(int?page)
        {
            if (page == null)
            {
                page = 1;
            }

            var list = new CategoryDb().GetsCategories(0);

            int pageSize = 3;

            int pageNumber = (page ?? 1);

            return(View(list.ToPagedList(pageNumber, pageSize)));
        }
Beispiel #21
0
        public static void GetCustomersInCategory(string name)
        {
            IEnumerable <Customer> customers  = CustomerDb.GetAllCustomers();
            IEnumerable <Category> categories = CategoryDb.GetAllCategories();


            IEnumerable <CustomersGoods> customerGoodsDbs = CustomerGoodsDb.GetCustomerGoods();
            var listOfCategories = categories.Where(p => p.Name == name);

            var needProducts = listOfCategories.Join(customerGoodsDbs,
                                                     c => c.Product.IdGoods, cg => cg.Product.IdGoods, (c, cg) => new { Id = cg.Customer.IdCustomer });

            var result = needProducts.Join(customers, arg => arg.Id, c => c.IdCustomer,
                                           (arg, c) => new { Name = c.Name });
        }
Beispiel #22
0
        private void AddCategories()
        {
            var parent1 = new CategoryDb()
            {
                Code      = "Parent 1",
                ForEntity = "bun"
            };
            var parent2 = new CategoryDb()
            {
                Code      = "Parent 2",
                ForEntity = "bun"
            };
            var parent3 = new CategoryDb()
            {
                Code      = "Parent 3",
                ForEntity = "ceva"
            };


            context.Categories.Add(parent1);
            context.Categories.Add(parent2);
            context.Categories.Add(parent3);
            context.SaveChanges();

            var children = new List <CategoryDb> {
                new CategoryDb()
                {
                    Code      = "Child 1",
                    ForEntity = "bun",
                    ParentId  = 1
                },
                new CategoryDb()
                {
                    Code      = "Child 2",
                    ForEntity = "bun",
                    ParentId  = 1
                },
                new CategoryDb()
                {
                    Code      = "Child 3",
                    ForEntity = "ceva",
                    ParentId  = 3
                }
            };

            context.Categories.AddRange(children);
            context.SaveChanges();
        }
Beispiel #23
0
        public void should_save_category_in_db()
        {
            CategoryEdit categoryEdit = new()
            {
                Id   = -123,
                Name = "test name",
            };
            CategoryDb categoryDb = categoryEdit.MapToCategoryDb();

            _categories.Setup(n => n.Update(categoryDb)).Returns(categoryDb);
            _mapper.Setup(n => n.Map <CategoryDb>(categoryEdit)).Returns(categoryDb);

            _sut.Save(categoryEdit);

            _categories.Verify(n => n.Update(categoryDb));
        }
Beispiel #24
0
        public static void GetCustomerWithMostCategories()
        {
            var customersHasGoods = CustomerGoodsDb.GetCustomerGoods();
            var categories        = CategoryDb.GetAllCategories();

            var subresult = customersHasGoods.Join(
                categories,
                cg => cg.Product.IdGoods,
                category => category.Product.IdGoods,
                (cg, category) => new { Category = category, Customer = cg.Customer, Goods = category.Product });

            var preres = subresult.GroupBy(r => r.Customer.Surname).Select(g => new { Name = g.Key, Count = g.Count() });
            var res    = preres.OrderByDescending(n => n.Count).First();

            Console.WriteLine("Максимально разнообразный {0} - у него товары в {1} категориях", res.Name, res.Count);
        }
Beispiel #25
0
        // GET: Admin/Product
        public ActionResult Index(string searchString = "", int categoryID = 0)
        {
            var categories = new CategoryDb().GetCategories(ref err, 0);

            ViewBag.categoryID = new SelectList(categories, "ID", "Name");

            var products = (IEnumerable <Product>) new ProductDb().GetProducts(ref err, 0);

            if (!string.IsNullOrEmpty(searchString))
            {
                products = products.Where(x => x.Alias.ToLower().Contains(searchString.ToLower()));
            }
            if (categoryID != 0)
            {
                products = products.Where(x => x.CategoryID == categoryID);
            }
            return(View(products));
        }
Beispiel #26
0
 public static bool IsExists(string c)
 {
     try
     {
         if (!CategoryDb.CheckByName(c))
         {
             return(false);
         }
         else
         {
             return(true);
         }
     }
     catch
     {
         return(true);
     }
 }
Beispiel #27
0
        // GET: Admin/Product
        public ActionResult Index(string searching, int categoryID = 0)
        {
            var categories = new CategoryDb().GetCategories(ref err, 0);

            ViewBag.categoryID = new SelectList(categories, "ID", "Name"); // danh sách Category


            var products = (IEnumerable <Product>) new ProductDb().GetProducts(ref err, 0);

            if (!string.IsNullOrEmpty(searching))
            {
                products = products.Where(s => s.Alias.Contains(searching));
            }
            if (categoryID > 0)
            {
                products = products.Where(s => s.CategoryID == categoryID);
            }
            return(View(products));
        }
 public ActionResult Edit(int id, Category model)
 {
     try
     {
         var result = new CategoryDb().InsertUpdateCategory(ref err, ref rows, model);
         if (result && ModelState.IsValid)
         {
             return(RedirectToAction("Index", "Category", new  { Area = "Admin" }));
         }
         else
         {
             ModelState.AddModelError("", string.Format("Error: {0}", err));
         }
     }
     catch (Exception ex)
     {
         err = ex.Message;
     }
     return(View(model));
 }
 public ActionResult Create(Category model)
 {
     try{
         var result = new CategoryDb().InsertUpdateCategory(model);
         if (result != 0 & ModelState.IsValid)
         {
             //Luu session
             //Tra ve view index
             return(RedirectToAction("Index"));
         }
         else
         {
             ModelState.AddModelError("", "Luu khong thanh cong");
         }
     }
     catch (Exception ex)
     {
         ViewBag.error = ex.Message;
     }
     return(View(model));
 }
Beispiel #30
0
        // GET: Category/Details/5
        public ActionResult Details(int id)
        {
            var category = new CategoryDb().GetCategoryByID(ref err, id);

            if (category != null)
            {
                return(View(category));
            }
            else
            {
                if (!string.IsNullOrEmpty(err))
                {
                    ViewBag.Err = string.Format("Lỗi: {0}", err);
                }
                else
                {
                    ViewBag.Err = "Category khong co giá trị";
                }
            }
            return(View());
        }