public ActionResult Create()
        {
            CategoryDataAccess cda = new CategoryDataAccess();

            ViewData["cats"] = cda.GetAllCategories();
            return(View());
        }
        public void CategoryDataAccess_CrudCategory()
        {
            var categoryDataAccess = new CategoryDataAccess(new DbHelper(new SQLitePlatformWinRT(), new TestDatabasePath()));

            const string firstName = "category";
            const string secondName = "new category";

            var category = new Category
            {
                Name = firstName
            };

            categoryDataAccess.Save(category);

            categoryDataAccess.LoadList();
            var list = categoryDataAccess.LoadList();

            Assert.AreEqual(1, list.Count);
            Assert.AreEqual(firstName, list.First().Name);

            category.Name = secondName;
            categoryDataAccess.Save(category);

            list = categoryDataAccess.LoadList();

            Assert.AreEqual(1, list.Count);
            Assert.AreEqual(secondName, list.First().Name);

            categoryDataAccess.Delete(category);

            list = categoryDataAccess.LoadList();
            Assert.IsFalse(list.Any());
        }
Exemplo n.º 3
0
 public ActionResult CreateEdit(CategoryViewModel model)
 {
     try
     {
         if (ModelState.IsValid)
         {
             if (CategoryDataAccess.Update(model))
             {
                 return(Json(new { success = true, message = "berhasil" }, JsonRequestBehavior.AllowGet));
             }
             else
             {
                 return(Json(new { success = false, mesage = CategoryDataAccess.Message }, JsonRequestBehavior.AllowGet));
             }
         }
         else
         {
             return(Json(new { succes = false, message = "Please full fill required fields!" }, JsonRequestBehavior.AllowGet));
         }
     }
     catch (Exception ex)
     {
         return(Json(new { success = false, message = ex.Message }, JsonRequestBehavior.AllowGet));
     }
 }
Exemplo n.º 4
0
        public void CategoryDataAccess_CrudCategory()
        {
            var categoryDataAccess = new CategoryDataAccess();

            const string firstName  = "category";
            const string secondName = "new category";

            var category = new Category {
                Name = firstName
            };

            categoryDataAccess.Save(category);

            categoryDataAccess.LoadList();
            var list = categoryDataAccess.LoadList();

            Assert.AreEqual(1, list.Count);
            Assert.AreEqual(firstName, list.First().Name);

            category.Name = secondName;
            categoryDataAccess.Save(category);

            list = categoryDataAccess.LoadList();

            Assert.AreEqual(1, list.Count);
            Assert.AreEqual(secondName, list.First().Name);

            categoryDataAccess.Delete(category);

            list = categoryDataAccess.LoadList();
            Assert.IsFalse(list.Any());
        }
Exemplo n.º 5
0
 public CategoryService()
 {
     if (CategoryService.categoryDataAccess == null)
     {
         CategoryService.categoryDataAccess = new CategoryDataAccess();
     }
 }
        public void CategoryDataAccess_CrudCategory()
        {
            var categoryDataAccess =
                new CategoryDataAccess(new SqliteConnectionCreator(new WindowsSqliteConnectionFactory()));

            const string firstName = "category";
            const string secondName = "new category";

            var category = new Category
            {
                Name = firstName
            };

            categoryDataAccess.SaveItem(category);

            categoryDataAccess.LoadList();
            var list = categoryDataAccess.LoadList();

            Assert.Equal(1, list.Count);
            Assert.Equal(firstName, list.First().Name);

            category.Name = secondName;
            categoryDataAccess.SaveItem(category);

            list = categoryDataAccess.LoadList();

            Assert.Equal(1, list.Count);
            Assert.Equal(secondName, list.First().Name);

            categoryDataAccess.DeleteItem(category);

            list = categoryDataAccess.LoadList();
            Assert.False(list.Any());
        }
Exemplo n.º 7
0
 private void btnDelete_Click(object sender, EventArgs e)
 {
     if (cateroryGridView.SelectedRows.Count > 0)
     {
         DataGridViewRow dataRow = cateroryGridView.SelectedRows[0];
         int.TryParse(dataRow.Cells["id"].Value.ToString(), out int id);
         if (id < 0)
         {
             MessageBox.Show("Invalid category id");
             return;
         }
         else
         {
             int success = CategoryDataAccess.DeleteCategory(id);
             if (success > 0)
             {
                 MessageBox.Show("successfully deleted");
                 frmCategory_Load(sender, e);
             }
         }
     }
     else
     {
         MessageBox.Show("Please select a category to delete");
         return;
     }
 }
        public void CategoryDataAccess_CrudCategory()
        {
            var categoryDataAccess = new CategoryDataAccess();

            const string firstName = "category";
            const string secondName = "new category";

            var category = new Category
            {
                Name = firstName
            };

            categoryDataAccess.Save(category);

            categoryDataAccess.LoadList();
            var list = categoryDataAccess.LoadList();

            Assert.AreEqual(1, list.Count);
            Assert.AreEqual(firstName, list.First().Name);

            category.Name = secondName;
            categoryDataAccess.Save(category);

            list = categoryDataAccess.LoadList();

            Assert.AreEqual(1, list.Count);
            Assert.AreEqual(secondName, list.First().Name);

            categoryDataAccess.Delete(category);

            list = categoryDataAccess.LoadList();
            Assert.IsFalse(list.Any());
        }
 public RegisteredVehicleController()
 {
     _vehicle      = new RegisteredVehicleDataAccess();
     _service      = new RegisteredVehicleService();
     _manufacturer = new ManufacturerDataAccess();
     _category     = new CategoryDataAccess();
 }
Exemplo n.º 10
0
        public List <Food> GetAllFoodsByCategory(string categoryName)
        {
            CategoryDataAccess categoryDataAccess = new CategoryDataAccess();
            int categoryId = categoryDataAccess.GetCategoryId(categoryName);

            this.foodDataAccess = new FoodDataAccess();
            return(this.foodDataAccess.GetFoodsByCategoryId(categoryId));
        }
Exemplo n.º 11
0
        public ActionResult Create()
        {
            ViewBag.CategoryList = new SelectList(CategoryDataAccess.GetAll(), "CategoryCode", "CategoryName");

            ViewBag.ItemList = new SelectList(ItemDataAccess.GetByCategory(""), "ItemCode", "ItemName");

            return(View());
        }
Exemplo n.º 12
0
        public ActionResult Category(int cateId)
        {
            var productcategory = new CategoryDataAccess().ViewDetail(cateId);

            ViewBag.Category = productcategory;
            var model = new ProductDataAccess().ListByCategoryId(cateId);

            return(View(model));
        }
Exemplo n.º 13
0
        public async Task <IActionResult> Put(int id, [FromBody] UpdateCategoryMaster category)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(Ok(new OperationResponse
                    {
                        HasSucceeded = false,
                        IsDomainValidationErrors = true,
                        StatusCode = ((int)ResponseStatus.BadRequest).ToString(),
                        Message = string.Join("; ", ModelState.Values
                                              .SelectMany(x => x.Errors)
                                              .Select(x => x.ErrorMessage))
                    }));
                }

                CategoryDataAccess _categoryAccess = new CategoryDataAccess(_iconfiguration);

                DatabaseResponse response = await _categoryAccess.UpdateCategory(category, id);

                if (response.ResponseCode == (int)DbReturnValue.UpdateSuccess)
                {
                    return(Ok(new OperationResponse
                    {
                        HasSucceeded = true,
                        IsDomainValidationErrors = false,
                        Message = EnumExtensions.GetDescription(DbReturnValue.UpdateSuccess),
                        ReturnedObject = response.Results
                    }));
                }
                else
                {
                    Log.Error(EnumExtensions.GetDescription(DbReturnValue.UpdationFailed));

                    return(Ok(new OperationResponse
                    {
                        HasSucceeded = false,
                        IsDomainValidationErrors = false,
                        Message = EnumExtensions.GetDescription(DbReturnValue.NotExists),
                        ReturnedObject = response.Results
                    }));
                }
            }
            catch (Exception ex)
            {
                Log.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical));

                return(Ok(new OperationResponse
                {
                    HasSucceeded = false,
                    Message = StatusMessages.ServerError,
                    StatusCode = ((int)ResponseStatus.ServerError).ToString(),
                    IsDomainValidationErrors = false
                }));
            }
        }
Exemplo n.º 14
0
 private void ViewEditData()
 {
     category = CategoryDataAccess.GetCategoryById(categoryId);
     if (category != null)
     {
         txtCategory.Text  = category.CategoryName;
         chkActive.Checked = category.IsActive;
     }
 }
 public ManagerCollection()
 {
     _dataAccess = new CategoryDataAccess();
     _account    = new AccountDataAccess();
     _cats       = new List <Category>();
     _invs       = new List <Invoice>();
     _buss       = new List <Business>();
     SetCategories();
 }
Exemplo n.º 16
0
        public ActionResult Edit(int id)
        {
            VarianViewModel model = VarianDataAccess.GetById(id);

            ViewBag.CategoryList = new SelectList(CategoryDataAccess.GetAll(), "CategoryCode", "CategoryName");

            ViewBag.ItemList = new SelectList(ItemDataAccess.GetByCategory(model.CategoryCode), "ItemCode", "ItemName");

            return(View(model));
        }
Exemplo n.º 17
0
        public void frmCategory_Load(object sender, EventArgs e)
        {
            DataTable dt = CategoryDataAccess.GetCategories();

            if (dt != null)
            {
                this.cateroryGridView.DataSource = dt;
                FormatGrid(ref this.cateroryGridView);
            }
        }
Exemplo n.º 18
0
        public ActionResult Edit(Category cat)
        {
            CategoryDataAccess cda = new CategoryDataAccess();
            int i = cda.UpdateCategory(cat);

            if (i > 0)
            {
                return(RedirectToAction("Index"));
            }
            return(View());
        }
Exemplo n.º 19
0
        public ActionResult ConfirmDelete(int id)
        {
            CategoryDataAccess cda = new CategoryDataAccess();
            int i = cda.DeleteCategory(id);

            if (i > 0)
            {
                return(RedirectToAction("Index"));
            }
            return(View());
        }
Exemplo n.º 20
0
        public ActionResult Create(Category cat)
        {
            CategoryDataAccess cda = new CategoryDataAccess();
            int i = cda.InsertCategory(cat);

            if (i > 0)
            {
                return(RedirectToAction("Index"));
            }
            return(View());
        }
Exemplo n.º 21
0
 public ActionResult DeleteConfirm(int id)
 {
     if (CategoryDataAccess.Delete(id))
     {
         return(Json(new { success = true, message = "Sukses" }, JsonRequestBehavior.AllowGet));
     }
     else
     {
         return(Json(new { success = false, message = CategoryDataAccess.Message }, JsonRequestBehavior.AllowGet));
     }
 }
Exemplo n.º 22
0
 private void frmProductAdd_Load(object sender, EventArgs e)
 {
     keyValues = CategoryDataAccess.GetCategoriesForProduct();
     if (keyValues != null)
     {
         foreach (var item in keyValues)
         {
             cmbCategory.Items.Add(item.Value);
             categoryIds.Add(item.Key);
         }
     }
 }
        public void TestInitCategory()
        {
            //making sure the table is empty
            TestBuisness.clearAllTable();

            cat1         = new Category();
            cat2         = new Category();
            cat3         = new Category();
            cat1.catName = "food";
            cat2.catName = "sport";
            cat3.catName = "Entertaiment";
            cat_da       = new CategoryDataAccess();
        }
Exemplo n.º 24
0
        public CreateBook()
        {
            InitializeComponent();
            pubYearCmb.ItemsSource   = Enumerable.Range(1950, DateTime.UtcNow.Year - 1948).ToList();
            pubYearCmb.SelectedIndex = 12;
            // Load categories to the combo box
            CategoryDataAccess categoryDataAccess = new CategoryDataAccess();
            List <Category>    categories         = categoryDataAccess.AllCategories();

            categoriesCmb.ItemsSource       = categories;
            categoriesCmb.SelectedValuePath = "CategoryId";
            categoriesCmb.DisplayMemberPath = "CategoryName";
            categoriesCmb.SelectedValue     = 2;
        }
Exemplo n.º 25
0
 private void ViewCategories()
 {
     keyValues = CategoryDataAccess.GetCategoriesForProduct();
     if (keyValues != null)
     {
         cmbCategory.Items.Add("All");
         foreach (var item in keyValues)
         {
             cmbCategory.Items.Add(item.Value);
             categoryIds.Add(item.Key);
         }
     }
     cmbCategory.SelectedIndex = 0;
 }
Exemplo n.º 26
0
        public async Task <IActionResult> Get()
        {
            try
            {
                var parameters    = HttpUtility.ParseQueryString(Request.QueryString.Value);
                var paramIsActive = parameters["IsActive"];

                CategoryDataAccess _categoryAccess = new CategoryDataAccess(_iconfiguration);



                DatabaseResponse response = await _categoryAccess.GetCategories(paramIsActive);


                if (response.ResponseCode == (int)DbReturnValue.RecordExists)
                {
                    return(Ok(new OperationResponse
                    {
                        HasSucceeded = true,
                        IsDomainValidationErrors = false,
                        Message = EnumExtensions.GetDescription(DbReturnValue.RecordExists),
                        ReturnedObject = response.Results
                    }));
                }
                else
                {
                    Log.Error(EnumExtensions.GetDescription(DbReturnValue.NoRecords));

                    return(Ok(new OperationResponse
                    {
                        HasSucceeded = false,
                        IsDomainValidationErrors = false,
                        Message = EnumExtensions.GetDescription(DbReturnValue.NoRecords)
                    }));
                }
            }
            catch (Exception ex)
            {
                Log.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical));

                return(Ok(new OperationResponse
                {
                    HasSucceeded = false,
                    Message = StatusMessages.ServerError,
                    StatusCode = ((int)ResponseStatus.ServerError).ToString(),
                    IsDomainValidationErrors = false
                }));
            }
        }
Exemplo n.º 27
0
        public int AddNewFood(string foodName, double foodprice, string categoryName)
        {
            CategoryDataAccess categoryDataAccess = new CategoryDataAccess();
            int categoryId = categoryDataAccess.GetCategoryId(categoryName);

            Food food = new Food()
            {
                FoodName   = foodName,
                FoodPrice  = foodprice,
                CategoryId = categoryId
            };

            this.foodDataAccess = new FoodDataAccess();
            return(this.foodDataAccess.AddFood(food));
        }
Exemplo n.º 28
0
        public void DeleteFromDatabase_CategoryToDelete_CorrectlyDelete()
        {
            var category = new Category {
                Name = "categoryToDelete"
            };

            var dataAccess = new CategoryDataAccess(_connectionCreator);

            dataAccess.SaveItem(category);

            Assert.IsTrue(dataAccess.LoadList(x => x.Id == category.Id).Any());

            dataAccess.DeleteItem(category);
            Assert.IsFalse(dataAccess.LoadList(x => x.Id == category.Id).Any());
        }
Exemplo n.º 29
0
        public int UpdateExistingFood(int foodId, string foodName, double foodprice, string categoryName)
        {
            CategoryDataAccess categoryDataAccess = new CategoryDataAccess();
            int  categoryId = categoryDataAccess.GetCategoryId(categoryName);
            Food food       = new Food()
            {
                FoodId     = foodId,
                FoodName   = foodName,
                FoodPrice  = foodprice,
                CategoryId = categoryId
            };

            this.foodDataAccess = new FoodDataAccess();
            return(this.foodDataAccess.UpdateFood(food));
        }
        public int AddNewOrder(string customerName, int customerNumber, string orderdCategory, string orderdFood, int price, string DeliveryType, string categoryName)
        {
            CategoryDataAccess categoryDataAccess = new CategoryDataAccess();
            int categoryId = categoryDataAccess.GetCategoryId(categoryName);

            Order order = new Order()
            {
                CustomerName   = customerName,
                CustomerNumber = customerNumber,
                OrderdCategory = orderdCategory,
                OrderdFood     = orderdFood,
            };

            this.orderDataAccess = new OrderDataAccess();
            return(this.orderDataAccess.AddOrder(order));
        }
Exemplo n.º 31
0
 private void frmProductAdd_Load(object sender, EventArgs e)
 {
     keyValues = CategoryDataAccess.GetCategoriesForProduct();
     if (keyValues != null && cmbCategory.Items.Count < 1)
     {
         foreach (var item in keyValues)
         {
             cmbCategory.Items.Add(item.Value);
             categoryIds.Add(item.Key);
         }
     }
     if (productId > 0)
     {
         btnAdd.Text = "Update";
     }
 }
        public void SaveToDatabase_ExistingCategory_CorrectId()
        {
            var category = new Category();

            var dataAccess = new CategoryDataAccess(_connectionCreator);
            dataAccess.SaveItem(category);

            Assert.IsNull(category.Name);

            var id = category.Id;

            var name = "TestCategory";
            category.Name = name;

            Assert.AreEqual(id, category.Id);
            Assert.AreEqual(name, category.Name);
        }
Exemplo n.º 33
0
        public static void AddNewPreferencesDueToNewCustomer(CustomerEntity customer)
        {
            // Add all the categories as preferences.
            CustomerDataAccess customerDataAccess = new CustomerDataAccess();
            CategoryDataAccess categoryDataAccess = new CategoryDataAccess();

            foreach (CategoryEntity category in categoryDataAccess.LoadAll(false))
            {
                PreferenceEntity preference = new PreferenceEntity();
                preference.Active     = true;
                preference.Level      = 0;
                preference.Category   = category;
                preference.IdCustomer = customer.Id;
                preference.IsNew      = true;
                customer.Preferences.Add(preference);
            }
            customerDataAccess.Save(customer);
        }
Exemplo n.º 34
0
        public frmProductAdd(Form frmProduct, int userId, int productId)
        {
            this.frmProduct = frmProduct;
            this.userId     = userId;
            this.productId  = productId;
            InitializeComponent();

            keyValues = CategoryDataAccess.GetCategoriesForProduct();
            if (keyValues != null && cmbCategory.Items.Count < 1)
            {
                foreach (var item in keyValues)
                {
                    cmbCategory.Items.Add(item.Value);
                    categoryIds.Add(item.Key);
                }
            }

            ViewProductInfo();
        }
        public void SaveToDatabase_MultipleCategories_AllSaved()
        {
            var category1 = new Category
            {
                Name = "Einkaufen"
            };

            var category2 = new Category
            {
                Name = "Beer"
            };

            var dataAccess = new CategoryDataAccess(_connectionCreator);
            dataAccess.SaveItem(category1);
            dataAccess.SaveItem(category2);

            var resultList = dataAccess.LoadList();

            Assert.IsTrue(resultList.Any(x => x.Id == category1.Id && x.Name == category1.Name));
            Assert.IsTrue(resultList.Any(x => x.Id == category2.Id && x.Name == category2.Name));
        }
        public void DeleteFromDatabase_CategoryToDelete_CorrectlyDelete()
        {
            var category = new Category
            {
                Name = "categoryToDelete"
            };

            var dataAccess = new CategoryDataAccess(_connectionCreator);
            dataAccess.SaveItem(category);

            Assert.IsTrue(dataAccess.LoadList(x => x.Id == category.Id).Any());

            dataAccess.DeleteItem(category);
            Assert.IsFalse(dataAccess.LoadList(x => x.Id == category.Id).Any());
        }
        public void SaveToDatabase_CreateAndUpdateCategory_CorrectlyUpdated()
        {
            var firstName = "old name";
            var secondName = "new name";

            var category = new Category
            {
                Name = firstName
            };

            var dataAccess = new CategoryDataAccess(_connectionCreator);
            dataAccess.SaveItem(category);

            Assert.AreEqual(firstName, dataAccess.LoadList().FirstOrDefault(x => x.Id == category.Id).Name);

            category.Name = secondName;
            dataAccess.SaveItem(category);

            var categories = dataAccess.LoadList();
            Assert.IsFalse(categories.Any(x => x.Name == firstName));
            Assert.AreEqual(secondName, categories.First(x => x.Id == category.Id).Name);
        }