Exemple #1
0
        protected async Task ConfirmChangedHandlerAsync(bool deleteConfirmed)
        {
            if (deleteConfirmed)
            {
                if (Id == Guid.Empty)
                {
                    return;
                }

                try
                {
                    if (await CategoriesLogic.DeleteCategoryAsync(Id))
                    {
                        //TODO:Add message to notify the user
                        await UpdateCategoriesAsync();
                    }
                }
                catch (UserException e)
                {
                    Logger.LogError(e, e.Message);
                    await ShowErrorMessageAsync(e.Message);
                }
                catch (Exception e)
                {
                    Logger.LogError(e, e.Message);
                    await ShowErrorMessageAsync();
                }
            }
        }
        public ActionResult Create(CategoryEditor catEditor)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    var serviceInfo = new ServiceTypesLogics();
                    ViewBag.types = serviceInfo.GetServiceTypes().ToList().Select(x => new SelectListItem()
                    {
                        Value = x.Key.ToString(),
                        Text  = x.Value
                    });
                    return(View(catEditor));
                }

                CategoriesLogic catLogic = new CategoriesLogic();
                catEditor.State = ObjectStatus.ObjectState.Create; //Set the object's state to Create
                List <CategoryEditor> catEditList = new List <CategoryEditor>();
                catEditList.Add(catEditor);
                catLogic.EditCategories(catEditList);

                return(this.RedirectToAction("Index"));
            }
            catch
            {
                Console.WriteLine("Error creating new CategoryEditor");
                return(View());
            }
        }
        public void Setup()
        {
            this.mock = new Mock <IRepository <Categories> >();
            List <Categories> list = new List <Categories>()
            {
                new Categories()
                {
                    category_id = 31, category_name = "FILM AND ANIMATION", category_adult = 0
                },
                new Categories()
                {
                    category_id = 32, category_name = "COMEDY", category_adult = 0
                },
                new Categories()
                {
                    category_id = 33, category_name = "EDUCATION", category_adult = 0
                },
                new Categories()
                {
                    category_id = 34, category_name = "ENTERTAINMENT", category_adult = 0
                },
                new Categories()
                {
                    category_id = 37, category_name = "THRILLER", category_adult = 1
                },
                new Categories()
                {
                    category_id = 36, category_name = "GAMING", category_adult = 0
                }
            };

            this.mock.Setup(x => x.GetAll()).Returns(list.AsQueryable());

            this.logic = new CategoriesLogic(this.mock.Object);
        }
Exemple #4
0
        public async Task <IActionResult> NewCategory(Category model, IFormFile picture)
        {
            string photoPath;

            try
            {
                if (picture != null)
                {
                    photoPath = await _environment.AddFile(picture, "/img/");

                    model.PhotoPath = photoPath;
                }
            }
            catch (Exception e)
            {
                TempData.AddOrUpdate("CategoryError", e.Message);
                return(View("NewCategory"));
            }
            var message = CategoriesLogic.AddCategory(model);

            if (message.GetErrorMessage != null)
            {
                TempData.AddOrUpdate("CategoryError", message.GetErrorMessage);
            }
            return(View("NewCategory", message.GetModel));
        }
Exemple #5
0
        /// <summary>
        /// Occurs when the Sub Categories Grid View Selected index is changed
        /// Level: External
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvSubCategories_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                gvCategories.SelectedIndex    = -1;
                ReqValImage.Visible           = false;
                btnAdd.Visible                = false;
                btnUpdate.Visible             = true;
                lblServerSideErrorBottom.Text = "";
                lblServerSideErrorTop.Text    = "&nbsp;";

                Category myCategory = new CategoriesLogic().RetrieveCategoryByID(Convert.ToInt32(gvSubCategories.SelectedValue));
                txtCategory.Text = myCategory.Category1;

                imgSelectedCategory.Visible = true;

                imgSelectedCategory.ImageUrl = Page.ResolveClientUrl(myCategory.ImageURL);

                ddlParent.DataSource     = new CategoriesLogic().RetrieveParentCategories();
                ddlParent.DataTextField  = "Category1";
                ddlParent.DataValueField = "Id";
                ddlParent.DataBind();
                ddlParent.Items.Insert(0, new ListItem("Set: Parent", "0"));

                ddlParent.SelectedValue = myCategory.CategoryFK.ToString();
            }
            catch (Exception Exception)
            {
                throw Exception;
            }
        }
        // GET: CatagoryEditor
        public ActionResult Index()
        {
            CategoriesLogic ct         = new CategoriesLogic();
            var             categories = ct.GetCategories();

            return(this.View(categories));
        }
        public string RetrieveChildCategories(string ParentID)
        {
            try
            {
                if (Context.User.IsInRole("User"))
                {
                    List <Category> myCategories = new CategoriesLogic().RetrieveChildCategories(Convert.ToInt32(ParentID)).ToList();
                    string          HTML         = "<option value=\"0\">Select</option>";

                    foreach (Category myCategory in myCategories)
                    {
                        HTML += "<option value=\"" + myCategory.Id + "\">" + myCategory.Category1 + "</option>";
                    }

                    return(HTML);
                }
                else
                {
                    return("");
                }
            }
            catch (Exception Exception)
            {
                throw Exception;
            }
        }
        // GET: CatagoryEditor/Edit/5
        public ActionResult Edit(int id)
        {
            CategoriesLogic       ct             = new CategoriesLogic();
            List <CategoryEditor> catEditors     = ct.GetCategories();
            CategoryEditor        editedCategory = catEditors.Single(c => c.Id == id);

            return(View(editedCategory));
        }
        public void EmptyRepository()
        {
            Mock <IRepository <Categories> > empty = new Mock <IRepository <Categories> >();

            empty.Setup(x => x.GetAll()).Returns(new List <Categories>().AsQueryable());

            CategoriesLogic l = new CategoriesLogic(empty.Object);

            Assert.That(l.GetAll().Count(), Is.Zero);
        }
Exemple #10
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                MaintainScrollPositionOnPostBack = true;

                LoadProducts = true;

                if (!Page.IsPostBack)
                {
                    IQueryable <Category>      myCategories = new CategoriesLogic().RetrieveAllChildCategories();
                    IQueryable <SuppliersView> mySuppliers  = new SuppliersLogic().RetrieveAllSuppliers();

                    if ((mySuppliers.Count() > 0) && (myCategories.Count() > 0))
                    {
                        gvProducts.DataSource = new ProductsLogic().RetrieveAllProducts();
                        gvProducts.DataBind();

                        ddlStatus.Items.Add(new ListItem("Active", "true"));
                        ddlStatus.Items.Add(new ListItem("Inactive", "false"));

                        ddlCategory.DataSource     = myCategories;
                        ddlCategory.DataTextField  = "Category1";
                        ddlCategory.DataValueField = "Id";
                        ddlCategory.DataBind();
                        ddlCategory.Items.Insert(0, new ListItem("Select", "0"));

                        ddlSupplier.DataSource     = mySuppliers;
                        ddlSupplier.DataTextField  = "Supplier";
                        ddlSupplier.DataValueField = "Id";
                        ddlSupplier.DataBind();
                        ddlSupplier.Items.Insert(0, new ListItem("Select", "0"));

                        LoadProducts = true;
                    }
                    else
                    {
                        lblServerSideError.Text = "Suppliers and Categories must be added in order to add Products";

                        LoadProducts = false;
                    }
                }
            }
            catch (Exception Exception)
            {
                throw Exception;
            }
        }
Exemple #11
0
        static void Main(string[] args)
        {
            Console.WriteLine("A continuación se muestran las categorías:");
            Console.WriteLine("");

            CategoriesLogic categoriesLogic = new CategoriesLogic();
            var             categories      = categoriesLogic.Categories();

            foreach (var item in categories)
            {
                Console.WriteLine($"ID: {item.CategoryID.ToString()} , NOMBRE: {item.CategoryName.ToString()}, DESCRIPCIÓN: {item.Description.ToString()} ");
            }

            Console.ReadKey();
            Console.Clear();


            Console.WriteLine("Ingrese un número de ID de Producto o ingrese 0 para finalizar.");
            Console.WriteLine("");
            string paramProducto = Console.ReadLine();

            while (paramProducto != "0")
            {
                int  i     = 0;
                bool EsInt = int.TryParse(paramProducto, out i);

                ProductsLogic productsLogic = new ProductsLogic();
                var           products      = productsLogic.Products();
                var           item          = productsLogic.Products(i);
                productsLogic.Products(i);
                if (EsInt && i < products.Count)
                {
                    Console.WriteLine($" ID: {item.ProductID} , NOMBRE: {item.ProductName} , ID DE PROVEEDOR: {item.SupplierID} , CATEGORIA: {item.CategoryID}, {System.Environment.NewLine} " +
                                      $"CANTIDAD POR UNIDAD: {item.QuantityPerUnit} , PRECIO UNITARIO: {item.UnitPrice} ,  UNIDADES EN STOCK: {item.UnitsInStock}, {System.Environment.NewLine} UNIDADES ENCARGADAS: {item.UnitsOnOrder} , PUNTO DE PEDIDO: {item.ReorderLevel} , DESCONTINUADO: {item.Discontinued}");
                }
                else
                {
                    Console.WriteLine("");
                    Console.WriteLine($"Ingrese un valor numérico válido menor que {products.Count}");
                }
                Console.WriteLine("");
                Console.WriteLine("Ingrese otro número de ID de Producto o ingrese 0 para finalizar.");
                Console.WriteLine("");
                paramProducto = Console.ReadLine();
            }
            Console.WriteLine("Finalizó la consulta.");
            Console.ReadKey();
        }
Exemple #12
0
        /// <summary>
        /// Occurs when the Categories GridView item is Deleted
        /// Level: External
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvCategories_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            try
            {
                Category myCategory = new CategoriesLogic().RetrieveCategoryByID(Convert.ToInt32(e.Keys[0]));

                string PreviousURL = myCategory.ImageURL;

                if (new CategoriesLogic().DeleteCategory(myCategory.Id) == false)
                {
                    //deletion error, has sub categories
                    lblServerSideErrorTop.Text = "Category has Existing Child Categories and Cannot be Deleted";
                }
                else
                {
                    File.Delete(Server.MapPath(PreviousURL));

                    gvCategories.DataSource = new CategoriesLogic().RetrieveParentCategories();
                    gvCategories.DataBind();

                    gvSubCategories.DataSource = new CategoriesLogic().RetrieveChildCategories(Convert.ToInt32(gvCategories.SelectedValue));
                    gvSubCategories.DataBind();

                    lblServerSideErrorBottom.Text = "";
                    lblServerSideErrorTop.Text    = "&nbsp;";
                    gvCategories.SelectedIndex    = -1;
                    gvSubCategories.SelectedIndex = -1;
                    txtCategory.Text            = "";
                    imgSelectedCategory.Visible = false;
                    btnUpdate.Visible           = false;
                    ReqValImage.Visible         = true;
                    btnAdd.Visible = true;

                    ddlParent.DataSource     = new CategoriesLogic().RetrieveParentCategories();
                    ddlParent.DataTextField  = "Category1";
                    ddlParent.DataValueField = "Id";
                    ddlParent.DataBind();
                    ddlParent.Items.Insert(0, new ListItem("Set: Parent", "0"));
                }
            }
            catch (Exception Exception)
            {
                throw Exception;
            }
        }
Exemple #13
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Core"/> class.
        /// Set the menu object and draw menu.
        /// </summary>
        public Core()
        {
            List <string> items = new List <string>()
            {
                "Categories tábla kilistázása",
                "Categories rekord hozzáfűzés",
                "Categories rekord módosítás",
                "Categories rekord törlés",
                "Videos tábla kilistázása",
                "Videos rekord hozzáfűzés",
                "Videos rekord módosítás",
                "Videos rekord törlés",
                "Creators tábla kilistázása",
                "Creators rekord hozzáfűzés",
                "Creators rekord módosítás",
                "Creators rekord törlés",
                "Videók és a hozzá tartozó kategóriák listázása",
                "Videók, feltöltő nevének és nézettség listázása",
                "Top 5 legnézettebb videó",
                "Java végpont figyelése",
                "Program bezárása"
            };

            this.m = new Menu(items);

            this.categoriesLogic = new CategoriesLogic(new CategoryRepository());
            this.videosLogic     = new VideosLogic(new VideoRepository());
            this.creatorsLogic   = new CreatorsLogic(new CreatorRepository());
            this.nonCrudLogic    = new NonCrudLogic();
            this.webLogic        = new WebRequestLogic();

            while (this.m.SelectedMenuItemIndex != this.m.MenuItems.Count - 1)
            {
                this.m.PrintMenu();

                Console.WriteLine(this.m.MenuItems[this.m.SelectedMenuItemIndex]);

                this.CallQruery(this.m.SelectedMenuItemIndex);

                Console.Write("Nyomj meg egy gombot a folytatáshoz...");
                Console.ReadKey();
            }
        }
        public ActionResult Deactivate(CategoryEditor catEditor)
        {
            try
            {
                CategoriesLogic catLogic = new CategoriesLogic();
                catEditor.State = ObjectStatus.ObjectState.Delete; //Set the object's state to Delete
                List <CategoryEditor> catDelList = new List <CategoryEditor>();
                catDelList.Add(catEditor);

                catLogic.EditCategories(catDelList); //Sending the delete command to the CategoriesLogic object

                return(this.RedirectToAction("Index"));
            }
            catch
            {
                Console.WriteLine("Error deleting CategoryEditor " + catEditor.Id);
                return(View());
            }
        }
Exemple #15
0
        public void MyTestInitialize()
        {
            this.target = new CategoriesLogic();

            this.websiteCategory = new CategoryEditor
            {
                Active        = true,
                Crime         = true,
                Description   = "Test Cat",
                Id            = 1,
                Name          = "Edit Cat",
                CategoryTypes = new List <int> {
                    1
                },
                State = ObjectStatus.ObjectState.Read
            };

            this.databaseCategory = new ProviderServiceCategory
            {
                Active        = true,
                Crime         = false,
                Description   = "Test Cat",
                ID            = 1,
                CategoryTypes = new List <CategoryType> {
                    new CategoryType
                    {
                        ID            = 1,
                        CategoryId    = 1,
                        ServiceTypeId = 1,
                        ServiceType   = new ServiceType {
                            ID = 1, Name = "General"
                        }
                    }
                },
                Name = "Edit Cat",
            };

            this.categoryList = new List <CategoryEditor> {
                this.websiteCategory
            };
        }
Exemple #16
0
        public IActionResult DeleteCategory(string categoryName)
        {
            var result = CategoriesLogic.DeleteCategory(categoryName);

            if (result.GetErrorMessage == null)
            {
                if (result.GetModel != null)
                {
                    _environment.DeletePhoto(result.GetModel.PhotoPath);
                    TempData["CategoryDeletMessage"] = "Category deleted with photo";
                    return(RedirectToAction("Categories", "Product"));
                }
                else
                {
                    TempData["CategoryDeletMessage"] = "Category deleted without photo";
                    return(RedirectToAction("Categories", "Product"));
                }
            }
            TempData["CategoryDeletMessage"] = result.GetErrorMessage;
            return(RedirectToAction("Categories", "Product"));
        }
        public ActionResult Edit(CategoryEditor catEditor)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(catEditor));
                }
                CategoriesLogic catLogic = new CategoriesLogic();

                var catEditList = this.EditHelper(catEditor);
                catLogic.EditCategories(catEditList);

                return(this.RedirectToAction("Index"));
            }
            catch
            {
                Console.WriteLine("Error updating CategoryEditor " + catEditor.Id);
                return(View());
            }
        }
Exemple #18
0
 /// <summary>
 /// FamilyEditorsController constructor
 /// </summary>
 public FamilyEditorsController()
 {
     this.famLogic = new FamiliesLogic();
     this.catLogic = new CategoriesLogic();
 }
Exemple #19
0
        /// <summary>
        /// Occurs when the Update Button is Clicked
        /// Level: External
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            try
            {
                if (Page.IsValid)
                {
                    lblServerSideErrorBottom.Text = "";
                    lblServerSideErrorTop.Text    = "&nbsp;";

                    CategoryShift ShiftedAs = CategoryShift.Nothing;

                    if (gvCategories.SelectedIndex == -1)
                    {
                        //The Category is a Child

                        int    CategoryID = Convert.ToInt32(gvSubCategories.SelectedValue);
                        string Category   = txtCategory.Text.Trim();

                        if (ddlParent.SelectedIndex == 0)
                        {
                            //Set the Category as a Parent Category

                            Tuple <string, UploadResult> myTuple = UploadImage(fuImage);

                            if (myTuple.Item2 == UploadResult.Successful)
                            {
                                string PreviousURL = new CategoriesLogic().RetrieveCategoryByID(Convert.ToInt32(gvSubCategories.SelectedValue)).ImageURL;

                                if (new CategoriesLogic().AssignCategoryAsParent(CategoryID, Category, myTuple.Item1))
                                {
                                    File.Delete(Server.MapPath(PreviousURL));

                                    imgSelectedCategory.ImageUrl = Page.ResolveClientUrl(myTuple.Item1);

                                    ShiftedAs = CategoryShift.ChildToParent;
                                }
                                else
                                {
                                    File.Delete(Server.MapPath(myTuple.Item1));

                                    lblServerSideErrorTop.Text = "Category Already Exists or is Bound to One or More Products and Cannot be Elevated";

                                    ShiftedAs = CategoryShift.ChildCategoryError;
                                }
                            }
                            else if (myTuple.Item2 == UploadResult.NoImageFound)
                            {
                                if (new CategoriesLogic().AssignCategoryAsParent(CategoryID, Category, null))
                                {
                                    ShiftedAs = CategoryShift.ChildToParent;
                                }
                                else
                                {
                                    lblServerSideErrorTop.Text = "Category Already Exists or is Bound to One or More Products and Cannot be Elevated";

                                    ShiftedAs = CategoryShift.ChildCategoryError;
                                }
                            }
                            else
                            {
                                //inval extens
                                lblServerSideErrorBottom.Text = "Invalid Image Extension";
                                ShiftedAs = CategoryShift.Error;
                            }
                        }
                        else
                        {
                            //Set the Category as a Child Category

                            Tuple <string, UploadResult> myTuple = UploadImage(fuImage);

                            if (myTuple.Item2 == UploadResult.Successful)
                            {
                                string PreviousURL = new CategoriesLogic().RetrieveCategoryByID(Convert.ToInt32(gvSubCategories.SelectedValue)).ImageURL;

                                if (new CategoriesLogic().AssignCategoryAsChild(CategoryID, Category, myTuple.Item1, Convert.ToInt32(ddlParent.SelectedValue)))
                                {
                                    File.Delete(Server.MapPath(PreviousURL));
                                    imgSelectedCategory.ImageUrl = Page.ResolveClientUrl(myTuple.Item1);
                                    ShiftedAs = CategoryShift.ChildToChild;
                                }
                                else
                                {
                                    File.Delete(Server.MapPath(myTuple.Item1));
                                    lblServerSideErrorTop.Text = "Child Category Already Exists";
                                    ShiftedAs = CategoryShift.ChildCategoryError;
                                }
                            }
                            else if (myTuple.Item2 == UploadResult.NoImageFound)
                            {
                                if (new CategoriesLogic().AssignCategoryAsChild(CategoryID, Category, null, Convert.ToInt32(ddlParent.SelectedValue)))
                                {
                                    ShiftedAs = CategoryShift.ChildToChild;
                                }
                                else
                                {
                                    lblServerSideErrorTop.Text = "Child Category Already Exists";
                                    ShiftedAs = CategoryShift.ChildCategoryError;
                                }
                            }
                            else
                            {
                                //extension error
                                lblServerSideErrorBottom.Text = "Invalid Image Extension";
                                ShiftedAs = CategoryShift.Error;
                            }
                        }
                    }
                    else
                    {
                        //The Category is a Parent

                        int    CategoryID = Convert.ToInt32(gvCategories.SelectedValue);
                        string Category   = txtCategory.Text.Trim();

                        if (ddlParent.SelectedIndex == 0)
                        {
                            //Set the Category as a Parent Category

                            Tuple <string, UploadResult> myTuple = UploadImage(fuImage);

                            if (myTuple.Item2 == UploadResult.Successful)
                            {
                                string PreviousURL = new CategoriesLogic().RetrieveCategoryByID(Convert.ToInt32(gvCategories.SelectedValue)).ImageURL;

                                if (new CategoriesLogic().AssignCategoryAsParent(CategoryID, Category, myTuple.Item1))
                                {
                                    File.Delete(Server.MapPath(PreviousURL));

                                    imgSelectedCategory.ImageUrl = Page.ResolveClientUrl(myTuple.Item1);

                                    ShiftedAs = CategoryShift.ParentToParent;
                                }
                                else
                                {
                                    File.Delete(Server.MapPath(myTuple.Item1));

                                    lblServerSideErrorTop.Text = "Parent Category Already Exists";

                                    ShiftedAs = CategoryShift.Error;
                                }
                            }
                            else if (myTuple.Item2 == UploadResult.NoImageFound)
                            {
                                if (new CategoriesLogic().AssignCategoryAsParent(CategoryID, Category, null))
                                {
                                    ShiftedAs = CategoryShift.ParentToParent;
                                }
                                else
                                {
                                    lblServerSideErrorTop.Text = "Parent Category Already Exists";

                                    ShiftedAs = CategoryShift.Error;
                                }
                            }
                            else
                            {
                                //extension error
                                lblServerSideErrorBottom.Text = "Invalid Image Extension";
                                ShiftedAs = CategoryShift.Error;
                            }
                        }
                        else
                        {
                            //Set the Category as a Child Category

                            Tuple <string, UploadResult> myTuple = UploadImage(fuImage);
                            Category myCategory       = new CategoriesLogic().RetrieveCategoryByID(Convert.ToInt32(gvCategories.SelectedValue));
                            string   PreviousURL      = myCategory.ImageURL;
                            string   PreviousCategory = myCategory.Category1;

                            if (myTuple.Item2 == UploadResult.Successful)
                            {
                                if (new CategoriesLogic().AssignCategoryAsChild(CategoryID, Category, myTuple.Item1, Convert.ToInt32(ddlParent.SelectedValue)) == false)
                                {
                                    //error cannot sublevel this category
                                    File.Delete(Server.MapPath(myTuple.Item1));
                                    lblServerSideErrorTop.Text = "Category Already Exists or has Existing Child Categories and Cannot be Sub Levelled";
                                    ShiftedAs = CategoryShift.Error;
                                    ddlParent.SelectedIndex = 0;
                                    txtCategory.Text        = PreviousCategory;
                                }
                                else
                                {
                                    File.Delete(Server.MapPath(PreviousURL));
                                    ShiftedAs = CategoryShift.ParentToChild;
                                    imgSelectedCategory.ImageUrl = Page.ResolveClientUrl(myTuple.Item1);
                                }
                            }
                            else if (myTuple.Item2 == UploadResult.NoImageFound)
                            {
                                if (new CategoriesLogic().AssignCategoryAsChild(CategoryID, Category, null, Convert.ToInt32(ddlParent.SelectedValue)) == false)
                                {
                                    //error cannot sublevel this category
                                    lblServerSideErrorTop.Text = "Category Already Exists or has Existing Child Categories and Cannot be Sub Levelled";
                                    ShiftedAs = CategoryShift.Error;
                                    ddlParent.SelectedIndex = 0;
                                    txtCategory.Text        = PreviousCategory;
                                }
                                else
                                {
                                    ShiftedAs = CategoryShift.ParentToChild;
                                }
                            }
                            else
                            {
                                //extension error
                                lblServerSideErrorBottom.Text = "Invalid Image Extension";
                                ShiftedAs = CategoryShift.Error;
                            }
                        }
                    }

                    //Setting Grid Views Depending on Update Action
                    if (ShiftedAs == CategoryShift.ChildToChild)
                    {
                        Category myParentCategory = new CategoriesLogic().RetrieveCategoryByID(Convert.ToInt32(ddlParent.SelectedValue));

                        gvCategories.DataSource = new CategoriesLogic().RetrieveParentCategories();
                        gvCategories.DataBind();

                        foreach (GridViewRow myRow in gvCategories.Rows)
                        {
                            if (gvCategories.DataKeys[myRow.RowIndex].Value.Equals(myParentCategory.Id))
                            {
                                gvCategories.SelectedIndex = myRow.RowIndex;
                                break;
                            }
                        }

                        Category myChildCategory = new CategoriesLogic().RetrieveCategoryByID(Convert.ToInt32(gvSubCategories.SelectedValue));

                        gvSubCategories.DataSource = new CategoriesLogic().RetrieveChildCategories(Convert.ToInt32(gvCategories.SelectedValue));
                        gvSubCategories.DataBind();

                        foreach (GridViewRow myRow in gvSubCategories.Rows)
                        {
                            if (gvSubCategories.DataKeys[myRow.RowIndex].Value.Equals(myChildCategory.Id))
                            {
                                gvCategories.SelectedIndex    = -1;
                                gvSubCategories.SelectedIndex = myRow.RowIndex;
                                break;
                            }
                        }
                    }
                    else if (ShiftedAs == CategoryShift.ChildToParent)
                    {
                        Category myParentCategory = new CategoriesLogic().RetrieveCategoryByID(Convert.ToInt32(gvSubCategories.SelectedValue));

                        gvCategories.DataSource = new CategoriesLogic().RetrieveParentCategories();
                        gvCategories.DataBind();

                        foreach (GridViewRow myRow in gvCategories.Rows)
                        {
                            if (gvCategories.DataKeys[myRow.RowIndex].Value.Equals(myParentCategory.Id))
                            {
                                gvCategories.SelectedIndex = myRow.RowIndex;
                                break;
                            }
                        }

                        gvSubCategories.DataSource = new CategoriesLogic().RetrieveChildCategories(Convert.ToInt32(gvCategories.SelectedValue));
                        gvSubCategories.DataBind();
                    }
                    else if (ShiftedAs == CategoryShift.ParentToChild)
                    {
                        Category myChildCategory = new CategoriesLogic().RetrieveCategoryByID(Convert.ToInt32(gvCategories.SelectedValue));

                        gvSubCategories.DataSource = new CategoriesLogic().RetrieveChildCategories(Convert.ToInt32(ddlParent.SelectedValue));
                        gvSubCategories.DataBind();

                        foreach (GridViewRow myRow in gvSubCategories.Rows)
                        {
                            if (gvSubCategories.DataKeys[myRow.RowIndex].Value.Equals(myChildCategory.Id))
                            {
                                gvSubCategories.SelectedIndex = myRow.RowIndex;
                                break;
                            }
                        }

                        gvCategories.DataSource = new CategoriesLogic().RetrieveParentCategories();
                        gvCategories.DataBind();
                        gvCategories.SelectedIndex = -1;
                    }
                    else if ((ShiftedAs == CategoryShift.ParentToParent) || (ShiftedAs == CategoryShift.Error) || (ShiftedAs == CategoryShift.ChildCategoryError))
                    {
                        //if ((gvCategories.SelectedIndex == -1) && (gvSubCategories.SelectedIndex == -1))
                        //{
                        //    gvCategories.DataSource = new CategoriesLogic().RetrieveParentCategories();
                        //    gvCategories.DataBind();

                        //    gvSubCategories.DataSource = new CategoriesLogic().RetrieveChildCategories(Convert.ToInt32(gvCategories.SelectedValue));
                        //    gvSubCategories.DataBind();
                        //}
                        //Error populating
                        if ((gvSubCategories.SelectedIndex == -1) && (gvCategories.SelectedIndex > -1))
                        {
                            Category myCategory = new CategoriesLogic().RetrieveCategoryByID(Convert.ToInt32(gvCategories.SelectedValue));

                            gvCategories.DataSource = new CategoriesLogic().RetrieveParentCategories();
                            gvCategories.DataBind();

                            foreach (GridViewRow myRow in gvCategories.Rows)
                            {
                                if (gvCategories.DataKeys[myRow.RowIndex].Value.Equals(myCategory.Id))
                                {
                                    gvCategories.SelectedIndex = myRow.RowIndex;
                                    break;
                                }
                            }

                            gvSubCategories.DataSource = new CategoriesLogic().RetrieveChildCategories(Convert.ToInt32(gvCategories.SelectedValue));
                            gvSubCategories.DataBind();

                            txtCategory.Text        = myCategory.Category1;
                            ddlParent.SelectedValue = "0";
                            //dropdown??
                        }
                        else if ((gvCategories.SelectedIndex == -1) && (gvSubCategories.SelectedIndex > -1))
                        {
                            Category mySubCategory = new CategoriesLogic().RetrieveCategoryByID(Convert.ToInt32(gvSubCategories.SelectedValue));

                            gvSubCategories.DataSource = new CategoriesLogic().RetrieveChildCategories(Convert.ToInt32(mySubCategory.CategoryFK));
                            gvSubCategories.DataBind();

                            foreach (GridViewRow myRow in gvSubCategories.Rows)
                            {
                                if (gvSubCategories.DataKeys[myRow.RowIndex].Value.Equals(mySubCategory.Id))
                                {
                                    gvSubCategories.SelectedIndex = myRow.RowIndex;
                                    break;
                                }
                            }

                            txtCategory.Text        = mySubCategory.Category1;
                            ddlParent.SelectedValue = mySubCategory.CategoryFK.ToString();
                            //dropdown??
                        }
                    }
                }
            }
            catch (Exception Exception)
            {
                throw Exception;
            }
        }
Exemple #20
0
 public async Task UpdateCategoriesAsync()
 {
     Categories = await CategoriesLogic.GetCategoriesAsync();
 }
 public CategoryEditorController()
 {
     //TODO: change to global initialization
     this.catLogic = new CategoriesLogic();
 }