public async Task <JsonResult> AddSubcategory(CreateSubcategoryViewModel csvm)
        {
            var data   = "Subcategory Added Failed !";
            var status = false;

            try
            {
                var firebase     = FirebaseConnection.FirebaseDatabase();
                var categoryList = await firebase.Child("subCategory").Child(csvm.category).OnceAsync <GetSubcategoryViewModel>();

                foreach (var categoryDetail in categoryList)
                {
                    if (categoryDetail.Object.subCategoryName.Equals(csvm.subCategoryName, StringComparison.CurrentCultureIgnoreCase))
                    {
                        data = "Subcategory Name Already Exist !";
                        return(Json(new { data = data, status = status }, JsonRequestBehavior.AllowGet));
                    }
                }
                csvm.subCategoryName = System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(csvm.subCategoryName.ToLower().Trim());
                var subCategoryAdded = await firebase.Child("subCategory").Child(csvm.category).PostAsync(csvm, true);

                data   = "Subcategory Added Successfully !";
                status = true;
            }
            catch (Exception subCategoryAddException)
            {
                var subCatgeoryError = subCategoryAddException.GetType().GetProperty("Reason").GetValue(subCategoryAddException, null);
            }
            return(Json(new { data = data, status = status }, JsonRequestBehavior.AllowGet));
        }
Esempio n. 2
0
        public async Task<IActionResult> Create(CreateSubcategoryViewModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return this.View(model);
            }

            await this.service.CreateSubcategoryAsync(model);

            return this.RedirectToAction("Index", "Home", new { area = string.Empty });
        }
        public async Task CreateSubcategoryAsync(CreateSubcategoryViewModel model)
        {
            var subcategory = new Subcategory
            {
                Name        = model.Name,
                Description = model.Description,
                CategoryId  = model.CategoryId,
            };

            await this.repository.AddAsync(subcategory);

            await this.repository.SaveChangesAsync();
        }
Esempio n. 4
0
        public ActionResult SubcategoryCreate()
        {
            //authorize admin
            if (acl.AuthorizeAdmin(User.Identity.GetUserId()) == false)
            {
                return(HttpNotFound());
            }

            var temp = new CreateSubcategoryViewModel();

            temp.Categoires = typel.Category_List();
            return(View(temp));
        }
Esempio n. 5
0
        public ActionResult SubcategoryCreate(CreateSubcategoryViewModel cur)
        {
            cur.Categoires = typel.Category_List();
            if (ModelState.IsValid)
            {
                var tocreate = new Subcategory
                {
                    Name       = cur.Name,
                    CategoryId = cur.SelectCategory,
                    Slug       = cur.Slug,
                    Hidden     = false
                };

                if (typel.AdminSubcategoryCreate(tocreate, cur.SelectCategory))
                {
                    return(RedirectToAction("CategoryDetail", new { cateID = cur.SelectCategory }));
                }
                TempData["CreateError"] = "Invalid Create of Subcategory. The category name or slug already exists";
                return(View(cur));
            }
            return(View(cur));
        }