public IActionResult updatesubcategory(SubCategoryModel obj)
        {
            _manager.updatesubcategory(obj);
            return(Ok("updated"));

            throw new Exception("Exception while updating subcategory to the storage.");
        }
        public void InsertThenUpdate_ShouldReflectChanges()
        {
            // Arrange
            var expectedValue = "*****@*****.**";
            var dummyString   = Guid.NewGuid().ToString().Replace("-", "");
            var dbModel       = new SubCategoryModel()
            {
                Description = dummyString,
            };

            // Act
            var newId = new SubCategoryRepository(AppState.ConnectionString)
                        .Insert(dbModel);
            var dbModel2 = new SubCategoryRepository(AppState.ConnectionString)
                           .Select(newId);

            dbModel2.Description = expectedValue;

            new SubCategoryRepository(AppState.ConnectionString)
            .Update(dbModel2);
            var actualValue = new SubCategoryRepository(AppState.ConnectionString)
                              .Select(newId)
                              .Description;

            // Assert
            Assert.AreEqual(expectedValue, actualValue);
        }
Beispiel #3
0
        /// <summary>
        /// Insert or Update in tbl_Location table -vinod
        /// </summary>
        /// <param name="Sub Category"></param>
        /// <returns></returns>
        public string InsertOrUpdate(SubCategoryModel SCM)
        {
            string          result  = string.Empty;
            bool            isExist = false;
            tbl_SubCategory subcategory;

            subcategory = this.GetByID(SCM.SubCategoryID.Trim());
            if (subcategory != null)
            {
                isExist = true;
            }
            else
            {
                subcategory = new tbl_SubCategory();
            }
            subcategory.CategoryID      = SCM.CategoryID;
            subcategory.SubCategoryID   = SCM.SubCategoryID;
            subcategory.SubCategoryDesc = SCM.SubCategoryDesc;
            if (!isExist)
            {
                return(result = this.Insert(subcategory));
            }
            else
            {
                return(result = this.Update(subcategory));
            }
        }
Beispiel #4
0
        public SubCategoryModel SubCategoryM()
        {
            SubCategoryModel       SubCategoryModel;
            List <tbl_Category>    Category    = null;
            List <tbl_SubCategory> SubCategory = null;

            try
            {
                SubCategoryModel = new SubCategoryModel();

                Category    = this.GetCategoryAll();
                SubCategory = this.GetSubCategoryAll();

                SubCategoryModel.Category    = Category;
                SubCategoryModel.SubCategory = SubCategory;

                return(SubCategoryModel);
            }
            catch (Exception ex)
            {
                return(null);
            }
            finally
            {
                Category    = null;
                SubCategory = null;
            }
        }
        public ActionResult SaveSubCategory(string prm = "")
        {
            SubCategoryModel objSubCategoryModel = new SubCategoryModel();

            try
            {
                //if prm(Paramter) is empty means Add condition else edit condition
                if (!String.IsNullOrEmpty(prm))
                {
                    int SubCategoryId;
                    //decrypt parameter and set in SubCategoryId variable
                    int.TryParse(CommonUtils.Decrypt(prm), out SubCategoryId);
                    //Get SubCategory detail by  SubCategory Id
                    serviceResponse     = objUtilityWeb.GetAsync(WebApiURL.SubCategory + "/GetSubCategoryById?SubCategoryId=" + SubCategoryId.ToString());
                    objSubCategoryModel = serviceResponse.StatusCode == HttpStatusCode.OK ? serviceResponse.Content.ReadAsAsync <SubCategoryModel>().Result : null;
                }
                CaegoryDropDown(objSubCategoryModel.CategoryID);
            }
            catch (Exception ex)
            {
                ErrorLog(ex, "SubCategory", "SaveSubCategory Get");
            }

            return(View("SaveSubCategory", objSubCategoryModel));
        }
 public static bool UpdateSubCategoryById(string idSubCategory, string idCategory, string name)
 {
     try
     {
         string[] subCategory = new string[] { idSubCategory, name };
         if (ValidateData.VerifyFields(subCategory))
         {
             SubCategoryModel subCategoryModel = new SubCategoryModel()
             {
                 IdsubCategory = int.Parse(idSubCategory),
                 IdCategory    = int.Parse(idCategory),
                 Name          = name
             };
             DBSubCategory.UpdateSubCategory(subCategoryModel);
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch (Exception ex)
     {
         //Log4Net
         return(false);
     }
 }
Beispiel #7
0
        public ActionResult Create(SubCategoryModel subCategory)
        {
            try
            {
                ViewBag.CategoryListItems = (IEnumerable <SelectListItem>)Session["CategoryListItems"] ?? GetCategoriesDropDownList();

                if (ModelState.IsValid)
                {
                    if (subCategoryService.Exists(subCategory.SubCategoryName))
                    {
                        DisplayWarningMessage($"Sub-Category Name '{subCategory.SubCategoryName}' is duplicate");
                        return(View(subCategory));
                    }

                    DropDownSubCategoryDto subCategoryModel = Mapper.Map <SubCategoryModel, DropDownSubCategoryDto>(subCategory);
                    subCategoryService.CreateSubCategory(subCategoryModel);
                    DisplaySuccessMessage($"New Sub-Category '{subCategory.SubCategoryName}' has been stored successfully");
                    Session["SelectedCategoryID"] = subCategory.CategoryID.ToString();
                    return(RedirectToAction("List"));
                }
            }
            catch (Exception exp)
            {
                DisplayUpdateErrorMessage(exp);
            }
            return(View(subCategory));
        }
        public void Put_WithMockedModel_ShouldBeCalledOnce()
        {
            // Arrange
            var actualId       = 7452;
            var dummyString    = Guid.NewGuid().ToString().Replace("-", "");
            var mockRepository = new Mock <ISubCategoryRepository>();
            var dbModel        = new SubCategoryModel()
            {
                Description = dummyString,
            };

            mockRepository
            .Setup(m => m.Update(dbModel));

            var controller = new SubCategoryController(mockRepository.Object);

            // Act
            controller.Put(actualId, dbModel);

            // Assert
            mockRepository
            .Verify(m => m.Update(
                        It.Is <SubCategoryModel>(
                            i => i.Id == actualId && i.Description == dummyString)),
                    Times.Once());
        }
Beispiel #9
0
        public async Task <ActionResult> BrowseByIDFromBrand(int SubCategoryID, int BrandID, int?Page)
        {
            SubCategoryModel subCategory = await db.SubCategories.FindAsync(SubCategoryID);

            BrandModel brand = await db.Brands.FindAsync(BrandID);

            int maxRows  = 4;
            int maxCols  = 4;
            int maxPages = decimal.ToInt32(decimal.Ceiling((decimal)subCategory.Products.Count / (decimal)(maxRows * maxCols)));
            IList <ProductModel> productPage = (from p in subCategory.Products where p.BrandID == brand.BrandID select p).Skip((maxRows * maxCols) * ((Page ?? 1) - 1)).Take(maxRows * maxCols).ToList();

            SubCategoryBrowseFromBrandViewModel viewModel = new SubCategoryBrowseFromBrandViewModel()
            {
                ParentBrand = brand, SubCategory = subCategory, SisterSubCategories = await db.GetBrandSubCategoriesAsync(brand.BrandID), ProductsPage = productPage
            };

            ViewBag.MaxRows  = maxRows;
            ViewBag.MaxCols  = maxCols;
            ViewBag.Page     = Page ?? 1;
            ViewBag.MaxPages = maxPages;

            await this.FillViewBag();

            return(View("BrowseFromBrand", viewModel));
        }
Beispiel #10
0
        // GET: SubCategory
        public ActionResult Index()
        {
            SubCategoryModel SCM = new SubCategoryModel();

            SCM = SubCategoryBL.SubCategoryM();
            return(View(SCM));
        }
Beispiel #11
0
        public async Task <ResponseModel> DeleteSubCategory(SubCategoryModel subCategoryModel)
        {
            ResponseModel response = new ResponseModel();

            try
            {
                response.Data = subCategoryModel;
                var         _context = _unitOfWork.GetRepoInstance <SubCategory>();
                SubCategory category = await _context.GetById(subCategoryModel.SubCategoryId);

                if (category == null)
                {
                    response.ErrorMessage = "SubCategory not found";
                    return(response);
                }

                _context.Delete(category);
                response.Status         = true;
                response.SuccessMessage = "SubCategory deleted successfully";
            }
            catch (Exception ex)
            {
                response.Status       = false;
                response.ErrorMessage = "Internal server error. Please contact administrator.";
            }
            return(response);
        }
Beispiel #12
0
        private void codeTextBox_KeyUp(object sender, KeyEventArgs e)
        {
            try
            {
                if (e.KeyCode == Keys.Enter)
                {
                    string       productCode  = codeTextBox.Text;
                    ProductModel productModel = ProductManagement.SelectProductByCode(productCode);

                    if (!SearchDuplicates(productCode))
                    {
                        SubCategoryModel subCategoryModel = SubCategoryManagement.SelectSubCategoryById(productModel.IdSubCategory.ToString());
                        string           tax   = "0,13";
                        decimal          taxes = (productModel.NormalPrice * decimal.Parse(tax));
                        dgvAparts.Rows.Add(productModel.IdProduct.ToString(), productModel.Code, productModel.Description, subCategoryModel.Name, 1, productModel.NormalPrice, productModel.NormalPrice, 0, taxes.ToString("##,##0.00"));
                    }
                    codeTextBox.Focus();
                    codeTextBox.Text = string.Empty;
                    setInformation();
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Beispiel #13
0
        public async Task <ActionResult> BrowseByIDFromCategory(int SubCategoryID, int CategoryID, int?Page)
        {
            SubCategoryModel subCategory = await db.SubCategories.FindAsync(SubCategoryID);

            CategoryModel category = await db.Categories.FindAsync(CategoryID);

            int maxRows  = 4;
            int maxCols  = 4;
            int maxPages = decimal.ToInt32(decimal.Ceiling((decimal)subCategory.Products.Count / (decimal)(maxRows * maxCols)));
            IList <ProductModel> productPage = (from p in subCategory.Products select p).Skip((maxRows * maxCols) * ((Page ?? 1) - 1)).Take(maxRows * maxCols).ToList();

            SubCategoryBrowseFromCategoryViewModel viewModel = new SubCategoryBrowseFromCategoryViewModel()
            {
                ParentCategory = category, SubCategory = subCategory, ProductsPage = productPage
            };

            ViewBag.MaxRows  = maxRows;
            ViewBag.MaxCols  = maxCols;
            ViewBag.Page     = Page ?? 1;
            ViewBag.MaxPages = maxPages;

            await this.FillViewBag();

            return(View("BrowseFromCategory", viewModel));
        }
Beispiel #14
0
        // GET: SubCategory/Edit/5
        public ActionResult Edit(int?id)
        {
            SubCategoryModel uiCategory = new SubCategoryModel();

            if (!id.HasValue)
            {
                DisplayWarningMessage("Looks like, the ID is missing in your request");
                return(RedirectToAction("List"));
            }

            try
            {
                if (!subCategoryService.Exists(id.Value))
                {
                    DisplayWarningMessage($"Sorry, We couldn't find the Sub-Category with ID: {id.Value}");
                    return(RedirectToAction("List"));
                }

                ViewBag.CategoryListItems = (IEnumerable <SelectListItem>)Session["CategoryListItems"] ?? GetCategoriesDropDownList();

                DropDownSubCategoryDto category = subCategoryService.GetSubCategory(id.Value);
                uiCategory = Mapper.Map <DropDownSubCategoryDto, SubCategoryModel>(category);
            }
            catch (Exception exp)
            {
                DisplayReadErrorMessage(exp);
            }

            return(View(uiCategory));
        }
Beispiel #15
0
        public ActionResult Edit(SubCategoryModel subCategory)
        {
            try
            {
                ViewBag.CategoryListItems = (IEnumerable <SelectListItem>)Session["CategoryListItems"] ?? GetCategoriesDropDownList();

                // || (!ModelState.IsValid && ModelState.Values.Count(p => p.Errors.Count > 0) == 1)
                if (ModelState.IsValid)
                {
                    if (subCategoryService.Exists(subCategory.SubCategoryName, subCategory.SubCategoryID))
                    {
                        DisplayWarningMessage($"Sub-Category Name '{subCategory.SubCategoryName}' is duplicate");
                        return(View(subCategory));
                    }

                    DropDownSubCategoryDto subCategoryDto = Mapper.Map <SubCategoryModel, DropDownSubCategoryDto>(subCategory);
                    subCategoryService.UpdateSubCategory(subCategoryDto);
                    DisplaySuccessMessage("Sub-Category has been updated successfully");
                    Session["SelectedCategoryID"] = subCategory.CategoryID.ToString();
                    return(RedirectToAction("List"));
                }
            }
            catch (Exception exp)
            {
                DisplayUpdateErrorMessage(exp);
            }
            return(View(subCategory));
        }
Beispiel #16
0
        public async Task <ActionResult> Edit([Bind(Include = "SubCategoryID, SubCategoryName, SubCategoryLogo")] SubCategoryModel subCategoryModel)
        {
            if (ModelState.IsValid)
            {
                if (!await(from sc in db.SubCategories where sc.SubCategoryID != subCategoryModel.SubCategoryID && sc.SubCategoryName.ToLower() == subCategoryModel.SubCategoryName.ToLower() select sc).AnyAsync())
                {
                    SubCategoryModel editedModel = await db.SubCategories.FindAsync(subCategoryModel.SubCategoryID);

                    editedModel.ParentCategories.Clear();

                    string[]             selectedCategoriesStrings = Request.Form.GetValues("CheckedCategories") ?? new string[] { };
                    List <CategoryModel> selectedCategoriesList    = new List <CategoryModel>();
                    foreach (string str in selectedCategoriesStrings)
                    {
                        CategoryModel cat = await db.Categories.FindAsync(Int32.Parse(str));

                        selectedCategoriesList.Add(cat);
                    }

                    editedModel.SubCategoryLogo  = subCategoryModel.SubCategoryLogo;
                    editedModel.SubCategoryName  = subCategoryModel.SubCategoryName;
                    editedModel.ParentCategories = selectedCategoriesList;
                    db.Entry(editedModel).State  = EntityState.Modified;
                    await db.SaveChangesAsync();

                    return(RedirectToAction("Index"));
                }
            }
            await this.FillViewBag();

            return(View(subCategoryModel));
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="name"></param>
 /// <param name="idCategory"></param>
 /// <returns></returns>
 public static bool InsertSubCategory(string name, string idCategory)
 {
     try
     {
         string[] subCategory = new string[] { name, idCategory };
         if (ValidateData.VerifyFields(subCategory))
         {
             SubCategoryModel subCategoryModel = new SubCategoryModel()
             {
                 IdCategory = int.Parse(idCategory),
                 Name       = name,
             };
             DBSubCategory.InsertSubCategory(subCategoryModel);
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch (Exception ex)
     {
         return(false);
         //Log4Net
     }
 }
 /// <summary>
 /// return all the names of the subcategories with like by name
 /// </summary>
 /// <param name="SubCategory"></param>
 /// <returns></returns>
 public static List <SubCategoryModel> SelectCatWithSub(SubCategoryModel subCategoryModel)
 {
     using (IDbConnection cnn = new MySqlConnection(LoadConnectionString()))
     {
         var output = cnn.Query <SubCategoryModel>("SELECT * FROM subcategory WHERE idCategory = @idCategory", subCategoryModel);
         return(output.ToList());
     }
 }
Beispiel #19
0
        public static SubCategoryModel CreateSubCategoryModel(Product p)
        {
            var newSubCategory = new SubCategoryModel();

            newSubCategory.IdSubCategory = p.SubCategory.IdSubCategory;
            newSubCategory.Name          = p.SubCategory.Name;
            return(newSubCategory);
        }
 // PUT: api/SubCategory/5
 public bool Put(int id, [FromBody] SubCategoryModel subCategoryModel)
 {
     if (id > 0)
     {
         return(_subCategoryService.UpdateSubCategory(id, subCategoryModel));
     }
     return(false);
 }
Beispiel #21
0
        public ActionResult EditSubCategory(int id)
        {
            SubCategoryModel vm = new SubCategoryModel();

            vm.subcategry = _adminRepository.GetSubCategorybyId(id);
            vm.categories = _adminRepository.GetAllCategory();
            return(View("NewSubCategory", vm));
        }
 public static SubCategoryModel SelectSubCategoryById(SubCategoryModel SubCategory)
 {
     using (IDbConnection cnn = new MySqlConnection(LoadConnectionString()))
     {
         var output = cnn.QuerySingle <SubCategoryModel>("SELECT * FROM subcategory WHERE idsubCategory = @idsubCategory", SubCategory);
         return(output);
     }
 }
Beispiel #23
0
        public ActionResult CreateSubCategory(Guid mainCategoryId)
        {
            //TODO: validate if ID exists
            var subCategoryModel = new SubCategoryModel {
                MainCategoryId = mainCategoryId
            };

            return(View(subCategoryModel));
        }
        public ActionResult SaveSubCategory(SubCategoryModel objSubCategoryModel, HttpPostedFileBase fileUpload)
        {
            try
            {
                if (ModelState.IsValid)
                {
                }

                if (fileUpload != null)
                {
                    string fileName        = string.Empty;
                    string destinationPath = string.Empty;
                    fileName = Path.GetFileName(fileUpload.FileName);
                    string       AttachmentType = Path.GetExtension(fileUpload.FileName);
                    Stream       fs             = fileUpload.InputStream;
                    BinaryReader br             = new BinaryReader(fs);
                    byte[]       bytes          = br.ReadBytes((Int32)fs.Length);
                    /// string ImageContent = Convert.ToBase64String(bytes);
                    objSubCategoryModel.AttachmentContent = bytes;
                    objSubCategoryModel.AttachmentName    = fileName;
                    objSubCategoryModel.AttachmentSize    = fs.Length;
                    objSubCategoryModel.AttachmentType    = AttachmentType;
                }
                objSubCategoryModel.IsActive  = true;
                objSubCategoryModel.CreatedBy = LoggedInUserID;

                //Insert or Update  SubCategory
                serviceResponse     = objUtilityWeb.PostAsJsonAsync(WebApiURL.SubCategory + "/InsertUpdateSubCategory", objSubCategoryModel);
                objSubCategoryModel = serviceResponse.StatusCode == HttpStatusCode.OK ? serviceResponse.Content.ReadAsAsync <SubCategoryModel>().Result : null;

                //if error code is 0 means  SubCategory saved successfully
                if (Convert.ToInt32(objSubCategoryModel.ErrorCode) == 0)
                {
                    // Set success message
                    TempData["SucessMessage"] = "SubCategory Saved Successfully";
                    return(RedirectToAction("ViewSubCategory", "SubCategory"));
                }
                else if (Convert.ToInt32(objSubCategoryModel.ErrorCode) == 52)
                {
                    //If Errorcode is  52 means SubCategory Name is duplicate set duplicate SubCategory error message.
                    objSubCategoryModel.Message     = "SubCategory Duplicate not allowed";
                    objSubCategoryModel.MessageType = CommonUtils.MessageType.Error.ToString().ToLower();
                }
                else
                {
                    //set Error Message if error code is greater than 0 but not 52 (duplicate)
                    objSubCategoryModel.Message     = "Error while adding record";
                    objSubCategoryModel.MessageType = CommonUtils.MessageType.Error.ToString().ToLower();
                }
                CaegoryDropDown(objSubCategoryModel.CategoryID);
            }
            catch (Exception ex)
            {
                ErrorLog(ex, "SubCategory", "SaveSubCategory POST");
            }
            return(View("SaveSubCategory", objSubCategoryModel));
        }
Beispiel #25
0
        public ActionResult NewSubCategory()
        {
            SubCategoryModel vm = new SubCategoryModel();

            vm.categories = _adminRepository.GetAllCategory();


            return(View(vm));
        }
Beispiel #26
0
 public ActionResult CreateSubCategory(SubCategoryModel model)
 {
     if (ModelState.IsValid)
     {
         this.subCategoryRepository.Create(model);
         return(this.RedirectToIndex());
     }
     return(View(model));
 }
Beispiel #27
0
        public async Task <ActionResult> DeleteConfirmed(int SubCategoryID)
        {
            SubCategoryModel subCategoryModel = await db.SubCategories.FindAsync(SubCategoryID);

            db.SubCategories.Remove(subCategoryModel);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
 /// <summary>
 /// return all the names of the subcategories with like by name
 /// </summary>
 /// <param name="SubCategory"></param>
 /// <returns></returns>
 public static List <SubCategoryModel> SelectSubCategoryNameLike(SubCategoryModel SubCategory)
 {
     using (IDbConnection cnn = new MySqlConnection(LoadConnectionString()))
     {
         SubCategory.Name += "%";
         var output = cnn.Query <SubCategoryModel>("SELECT * FROM subcategory WHERE Name LIKE @Name", SubCategory);
         return(output.ToList());
     }
 }
Beispiel #29
0
        public async Task <IActionResult> Delete(SubCategoryModel model)
        {
            if (!await iSubCategoryRepositiry.DeleteSubCategoryPost(model))
            {
                return(NotFound());
            }

            return(RedirectToAction(nameof(Index)));
        }
Beispiel #30
0
        public string InsertOrUpdateSubCategory(SubCategoryModel SCM)
        {
            tbl_SubCategory subcategory = new tbl_SubCategory();

            subcategory.CategoryID      = SCM.CategoryID;
            subcategory.SubCategoryID   = SCM.SubCategoryID;
            subcategory.SubCategoryDesc = SCM.SubCategoryDesc;
            return(SubCategoryBL.InsertOrUpdate(SCM));
        }
Beispiel #31
0
        /// <summary>
        /// Fills the list with subcategories found in the database, and fills the subcategories with their subcategories, until MaxRecursion
        /// level is reached, or all are accounted for. 
        /// </summary>
        /// <param name="db">The repository. Since read-only, any will do, but don't create one needlessly</param>
        /// <param name="ModelList">The list to fill</param>
        /// <param name="id">The id of the category, or null if primary categories are to be found</param>
        /// <param name="MaxRecursionLevel">0 means no recursion, only fill the current list.</param>
        private void ViewCategory_RecursivelyFillSubcategories(ForumRespository db, Forum_User CategoryReader, List<SubCategoryModel> ModelList, int id, int MaxRecursionLevel)
        {
            if (MaxRecursionLevel < 0) return;
            foreach (var SubCategory in db.GetSortedCategories(id))
            {
                if (!SubCategory.InheritPermissions && !db.CheckCategoryPermissions(SubCategory, CategoryReader, P => P.AllowView))
                    continue;
                SubCategoryModel SubModel = new SubCategoryModel() {
                    id = SubCategory.CategoryID,
                    Name = SubCategory.Name,
                    AllowPosts = SubCategory.AllowPosts
                };

                ModelList.Add(SubModel);
                if (!SubCategory.AllowPosts)
                {
                    ViewCategory_RecursivelyFillSubcategories(db, CategoryReader, SubModel.SubCategories, SubModel.id, MaxRecursionLevel - 1);
                }
                else
                {
                    IQueryable<Forum_Thread> Threads = db.GetSortedThreads(SubCategory.CategoryID);
                    SubModel.ThreadCount = Threads.Count();
                    if (SubModel.ThreadCount > 0)
                    {
                        SubModel.PostCount = Threads.Sum(T => T.Posts);
                        SubModel.LastPostTime = Threads.First().LastPostTime;
                    }
                }
            }
        }