public IHttpActionResult PostProductSubCategory(ProductSubCategory productSubCategory)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.ProductSubCategories.Add(productSubCategory);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (ProductSubCategoryExists(productSubCategory.Id))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = productSubCategory.Id }, productSubCategory));
        }
        public ProductSubCategory GetProductSubCategoryById(long Id)
        {
            using (SqlConnection connection = new SqlConnection(CommonUtility.ConnectionString))
            {
                SqlCommand command = new SqlCommand(StoreProcedure.GetProductSubCategoryById, connection);
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.Add(new SqlParameter("@Id", Id));

                try
                {
                    connection.Open();
                    SqlDataReader      reader   = command.ExecuteReader();
                    ProductSubCategory category = new ProductSubCategory();
                    category = UtilityManager.DataReaderMap <ProductSubCategory>(reader);
                    return(category);
                }
                catch (Exception e)
                {
                    throw new Exception("Exception retrieving reviews. " + e.Message);
                }
                finally
                {
                    connection.Close();
                }
            }
        }
Beispiel #3
0
        public void SaveProductSubCategory(ProductSubCategoryDetails productSubCategoryDetails)
        {
            ProductSubCategory dbproductSubCategory = context.ProductSubCategory.Find(productSubCategoryDetails.ProductSubCategoryId);

            if (dbproductSubCategory != null)
            {
                dbproductSubCategory.ProductSubCategoryId = productSubCategoryDetails.ProductSubCategoryId;
                dbproductSubCategory.ProductCategoryName  = productSubCategoryDetails.ProductCategoryName;
                dbproductSubCategory.CategoryDescription  = productSubCategoryDetails.CategoryDescription;
                dbproductSubCategory.SubCategorySeoId     = context.SEO.Where(c => c.MetaTagTitle == productSubCategoryDetails.SelectedMetaTagTitle).Select(c => c.SEOId).FirstOrDefault();
                dbproductSubCategory.ProductCategoryId    = context.ProductCategory.Where(c => c.ProductCategoryName == productSubCategoryDetails.SelectedCategoryName).Select(c => c.ProductCategoryId).FirstOrDefault();
            }
            else
            {
                ProductSubCategory productSubCategorie = new ProductSubCategory
                {
                    ProductSubCategoryId = Guid.NewGuid(),
                    ProductCategoryName  = productSubCategoryDetails.ProductCategoryName,
                    CategoryDescription  = productSubCategoryDetails.CategoryDescription,
                    SubCategorySeoId     = context.SEO.Where(c => c.MetaTagTitle == productSubCategoryDetails.SelectedMetaTagTitle).Select(c => c.SEOId).FirstOrDefault(),
                    ProductCategoryId    = context.ProductCategory.Where(c => c.ProductCategoryName == productSubCategoryDetails.SelectedCategoryName).Select(c => c.ProductCategoryId).FirstOrDefault()
                };
                context.ProductSubCategory.Add(productSubCategorie);
            }
            context.SaveChanges();
        }
        public bool UpdateProductSubCategory(ProductSubCategory category)
        {
            bool isUpdate = true;

            using (SqlConnection connection = new SqlConnection(CommonUtility.ConnectionString))
            {
                SqlCommand command = new SqlCommand(StoreProcedure.UpdateProductSubCategory, connection);
                command.CommandType = CommandType.StoredProcedure;

                foreach (var item in category.GetType().GetProperties())
                {
                    string name  = item.Name;
                    var    value = item.GetValue(category, null);
                    command.Parameters.Add(new SqlParameter("@" + name, value == null ? DBNull.Value : value));
                }

                try
                {
                    connection.Open();
                    command.ExecuteNonQuery();
                }
                catch (Exception e)
                {
                    isUpdate = false;
                    throw new Exception("Exception Updating Data." + e.Message);
                }
                finally
                {
                    connection.Close();
                }
            }
            return(isUpdate);
        }
Beispiel #5
0
 public ActionResult Edit(ProductSubCategory category)
 {
     category.ModifiedDate         = DateTime.Now;
     context.Entry(category).State = EntityState.Modified;
     context.SaveChanges();
     return(RedirectToAction("List"));
 }
        public IHttpActionResult PutProductSubCategory(string id, ProductSubCategory productSubCategory)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != productSubCategory.Id)
            {
                return(BadRequest());
            }

            db.Entry(productSubCategory).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProductSubCategoryExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
 public ActionResult UpdateSubProduct(int Id)
 {
     if (User.Identity.IsAuthenticated)
     {
         if (Id != 0)
         {
             ProductSubCategory selectedSubProduct = db.getSubProduct(Id) as ProductSubCategory;
             if (selectedSubProduct != null)
             {
                 prodSubView.AdminPanel          = db.getAdminPanel();
                 prodSubView.ProductSubCat       = selectedSubProduct;
                 prodSubView.ProductsCategorys   = db.getProductsCategory();
                 prodSubView.SubProductsCategory = db.getSubProducts();
                 prodSubView.MadeInId            = db.getMadeIn();
                 ViewBag.Category = new SelectList(prodSubView.ProductsCategorys, "Id", "ProductName", selectedSubProduct.ProductCategoryId);
                 ViewBag.MadeInId = new SelectList(prodSubView.MadeInId, "Id", "Names", selectedSubProduct.MadeInId);
                 return(View("GetSubProduct", prodSubView));
             }
             else
             {
                 return(HttpNotFound());
             }
         }
         else
         {
             return(HttpNotFound());
         }
     }
     else
     {
         return(RedirectToAction("Login", "Logon"));
     }
 }
Beispiel #8
0
        public ServiceRes GetSubCategoryMaster(int categoryId)
        {
            ServiceRes <List <ProductSubCategory> > serviceRes = new ServiceRes <List <ProductSubCategory> >();

            try
            {
                List <ProductSubCategory> subCategories = new List <ProductSubCategory>();
                SqlParameter[]            sqlParameter  = new SqlParameter[1];
                sqlParameter[0] = new SqlParameter {
                    ParameterName = "@categoryId", Value = categoryId
                };
                DataTable dtCities = SqlHelper.GetTableFromSP("Usp_GetSubCategory", sqlParameter);
                foreach (DataRow row in dtCities.Rows)
                {
                    ProductSubCategory businessCategory = new ProductSubCategory
                    {
                        SubCategoryId = Convert.ToInt32(row["Product_SubCategoryId"]),
                        Name          = Convert.ToString(row["SubCategory_Name"])
                    };
                    subCategories.Add(businessCategory);
                }
                serviceRes.Data       = subCategories;
                serviceRes.IsSuccess  = true;
                serviceRes.ReturnCode = "200";
                serviceRes.ReturnMsg  = "Sub Category master";
            }
            catch (Exception ex)
            {
                LogManager.WriteLog(ex);
            }
            return(serviceRes);
        }
Beispiel #9
0
        public static ProductSubCategoryViewModel ToVm(this ProductSubCategory model, IConfiguration config, ProductSubCategoryViewModel vm = null)
        {
            if (vm == null)
            {
                vm = new ProductSubCategoryViewModel();
            }

            vm.Id          = model.Id;
            vm.Name        = model.Name;
            vm.Description = model.Description;
            if (!string.IsNullOrEmpty(model.Picture))
            {
                //vm.ImageURL = string.Format("{0}/{1}/{2}/{3}", config.GetSection("FileUploadUrl").Value, FolderNames.INSURANCE, model.Vehicle.Id, model.Attachment);
                var imagePath = string.Format(@"{0}{1}\{2}\{3}\{4}\{5}",
                                              config.GetSection("FileUploadPath").Value,
                                              FolderNames.PRODUCT_CATEGORY,
                                              model.ProductCategoryId,
                                              FolderNames.PRODUCT_SUB_CATEGORY,
                                              model.Id,
                                              model.Picture);
                if (File.Exists(imagePath))
                {
                    vm.Picture = "data:image/jpg;base64," + ImageHelper.getThumnialImage(imagePath);
                }
            }
            vm.Picture  = model.Picture;
            vm.IsActive = model.IsActive.Value;

            return(vm);
        }
 private void buttonAddSubCategoryProductPage_Click(object sender, RoutedEventArgs e)
 {
     if (listViewProductPageCategoryTable.SelectedItem != null)
     {
         int            i = listViewProductPageCategoryTable.SelectedIndex;
         AddSubCategory addSubCategory = new AddSubCategory();
         ProductSubCategory         = new ProductSubCategory();
         addSubCategory.DataContext = listViewProductPageCategoryTable.SelectedItem;
         addSubCategory.ShowDialog();
         if (addSubCategory.SaveButtonPressed == true)
         {
             jackyDigitalXDBEntities.ProductSubCategories.Add(ProductSubCategory);
             jackyDigitalXDBEntities.SaveChanges();
             listViewProductPageCategoryTable.ItemsSource   = null;
             listViewProductPageCategoryTable.ItemsSource   = jackyDigitalXDBEntities.ProductCategories.ToList();
             listViewProductPageCategoryTable.SelectedIndex = i;
             Helper.ShowMessage1();
         }
         else
         {
             return;
         }
     }
     else
     {
         MessageBox.Show("Please select a Category first!");
     }
 }
        private void CreatBreadCrumbs(Product product)
        {
            try
            {
                ProductCategory    pc = ProductHandler.GetProductCategoryByProduct(product);
                HtmlGenericControl li = new HtmlGenericControl("li");
                HtmlGenericControl a  = new HtmlGenericControl("a");
                a.Attributes.Add("href", "/View/" + pc.ProductCatName);
                a.InnerText = pc.ProductCatName.ToUpper();
                li.Attributes.Add("class", "breadcrumb-item");
                li.Controls.Add(a);
                ProductBreadCrumbs.Controls.Add(li);

                ProductSubCategory ps  = ProductHandler.GetProductSubCategoryByProduct(product);
                HtmlGenericControl li2 = new HtmlGenericControl("li");
                HtmlGenericControl a2  = new HtmlGenericControl("a");
                a2.Attributes.Add("href", "/View/" + pc.ProductCatName + "/" + ps.ProductSubCatName);
                a2.InnerText = ps.ProductSubCatName.ToUpper();
                li2.Attributes.Add("class", "breadcrumb-item");
                li2.Controls.Add(a2);
                ProductBreadCrumbs.Controls.Add(li2);

                HtmlGenericControl li3 = new HtmlGenericControl("li");
                li3.InnerText = product.ProductName.ToUpper();
                li3.Attributes.Add("class", "breadcrumb-item-active");
                ProductBreadCrumbs.Controls.Add(li3);
            }
            catch (Exception e) {
                ProductBreadCrumbs.Controls.Clear();
                ProductBreadCrumbs.InnerText = "Error";
            }
        }
        public async Task <List <Product> > SearchItemBySubCategory(ProductSubCategory productSubCategory)
        {
            List <Items> items = await _context.Items.Where(e => e.Subcategoryname == productSubCategory.subCategoryName).ToListAsync();

            if (items == null)
            {
                return(null);
            }
            else
            {
                List <Product> products = items.Select(s => new Product
                {
                    productId       = s.Id,
                    productName     = s.Itemname,
                    categoryId      = s.Categoryid,
                    subCategoryId   = s.Subcategoryid,
                    categoryName    = s.Categoryname,
                    subCategoryName = s.Subcategoryname,
                    price           = s.Price,
                    description     = s.Description,
                    stockno         = s.Stockno,
                    remarks         = s.Remarks,
                    imageName       = s.Imagename,
                }).ToList();
                return(products);
            }
        }
Beispiel #13
0
        public ProductSubCategory Get(String ProductSubCategoryID)
        {
            try
            {
                SqlParameter[] paramList = new SqlParameter[] {
                    new SqlParameter("@ProductSubCategory", ProductSubCategoryID)
                };

                DataTable dt = Execute.RunSP_DataTable(Connection, "SPGET_ProductSubCategoryByID", paramList);


                ProductSubCategory obj = new ProductSubCategory();


                obj.CategoryID = Convert.ToString(dt.Rows[0]["ProductSubCatID"]);
                obj.Category   = Convert.ToString(dt.Rows[0]["ProductSubCategory"]);


                return(obj);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex);
            }
        }
 public ActionResult AddSubPruduct(ProductSubCategory subPrdCategory)
 {
     if (User.Identity.IsAuthenticated)
     {
         bool result = false;
         if (subPrdCategory != null)
         {
             if (subPrdCategory.Id == 0)
             {
                 result = db.insertSubProduct(subPrdCategory);
             }
             else
             {
                 result = db.updateSubProduct(subPrdCategory);
             }
             if (result)
             {
                 return(RedirectToAction("GetSubProduct"));
             }
             return(HttpNotFound());
         }
         else
         {
             return(HttpNotFound());
         }
     }
     else
     {
         return(RedirectToAction("Login", "Logon"));
     }
 }
        public async Task <IActionResult> PutProductSubCategory(int id, ProductSubCategory productSubCategory)
        {
            if (id != productSubCategory.Id)
            {
                return(BadRequest());
            }

            _context.Entry(productSubCategory).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProductSubCategoryExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        private List <ProductSuperCategory> CreateCategoryStructure(ImportSellableItemPipelineArgument arg, CommercePipelineExecutionContext context)
        {
            XDocument document = XDocument.Load(arg.XMlFilePath);
            List <ProductSuperCategory> productSuperCategoryList = new List <ProductSuperCategory>();
            //Super Category Creation
            var selectedSuperCategories = document.Descendants("Product").Where(r => r.Attribute("UserTypeID").Value == "Level1");

            foreach (var superCategory in selectedSuperCategories)
            {
                string superCategoryName           = superCategory.Element("Name").Value.ToString();
                ProductSuperCategory supercategory = new ProductSuperCategory();
                var superCategoryItem = CreateOrGetCategory(context, arg.Catalog, superCategoryName);
                if (superCategoryItem != null && superCategoryItem.Result != null)
                {
                    var tempCategory = superCategoryItem.Result;
                    //await AssociateCategory(context, arg.Catalog, tempCategory);
                    supercategory.SuperCategory = tempCategory;
                }

                List <ProductCategory> productCategoryList = new List <ProductCategory>();
                //Category Creation
                var selectedCategories = superCategory.Descendants("Product").Where(r => r.Attribute("UserTypeID").Value == "Level2");
                foreach (var category in selectedCategories)
                {
                    string          categoryName    = category.Element("Name").Value.ToString();
                    var             categoryItem    = CreateOrGetCategory(context, arg.Catalog, categoryName, superCategoryItem.Result.SitecoreId);
                    ProductCategory productCategory = new ProductCategory();
                    if (categoryItem != null && categoryItem.Result != null)
                    {
                        var tempCategory = categoryItem.Result;
                        //await AssociateCategory(context, arg.Catalog, tempCategory, superCategoryItem.Result.Id);
                        productCategory.Category = tempCategory;
                    }


                    List <ProductSubCategory> productSubCategoryList = new List <ProductSubCategory>();
                    //Sub Category Creation
                    var selectedSubCategories = category.Descendants("Product").Where(r => r.Attribute("UserTypeID").Value == "Level3");
                    foreach (var subCategory in selectedSubCategories)
                    {
                        string             subCategoryName    = subCategory.Element("Name").Value.ToString();
                        var                subCategoryItem    = CreateOrGetCategory(context, arg.Catalog, subCategoryName, categoryItem.Result.SitecoreId);
                        ProductSubCategory productSubCategory = new ProductSubCategory();
                        if (subCategoryItem != null && subCategoryItem.Result != null)
                        {
                            var tempCategory = subCategoryItem.Result;
                            //await AssociateCategory(context, arg.Catalog, tempCategory, subCategoryItem.Result.Id);
                            productSubCategory.SubCategory = tempCategory;
                        }
                        productSubCategoryList.Add(productSubCategory);
                    }
                    productCategory.ProductSubCategoryList = productSubCategoryList;
                    productCategoryList.Add(productCategory);
                }
                supercategory.ProductCategoryList = productCategoryList;
                productSuperCategoryList.Add(supercategory);
            }
            return(productSuperCategoryList);
        }
Beispiel #17
0
        public ActionResult Index()
        {
            ProductSubCategory category = new ProductSubCategory();

            category.ProductSubCategoryCollection = context.ProductSubCategory.OrderByDescending(x => x.ModifiedDate).ToList();
            category.ProductCategoryCollection    = context.ProductCategory.ToList();
            return(View(category));
        }
Beispiel #18
0
        public ActionResult Delete(ProductSubCategory category)
        {
            var catgory = context.ProductSubCategory.Find(category.ProductSubCategoryID);

            context.ProductSubCategory.Remove(catgory);
            context.SaveChanges();
            return(RedirectToAction("List"));
        }
        public IActionResult DeleteSubCategory([FromBody] int id)
        {
            ProductSubCategory data = _context.Set <ProductSubCategory>().FirstOrDefault(c => c.ProductSubCategoryId == id);

            _context.Entry(data).State = Microsoft.EntityFrameworkCore.EntityState.Deleted;
            _context.SaveChanges();
            return(Ok(true));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            ProductSubCategory productSubCategory = db.ProductSubCategories.Find(id);

            db.ProductSubCategories.Remove(productSubCategory);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public override async Task InitializeViewModel(string param)
        {
            if (HasInitialized)
            {
                return;
            }
            ProductCategory category = await DataManager.CategoryDataSource.GetById(param);

            List <ProductSubCategory> subCategories       = null;
            ProductSubCategory        selectedSubCategory = null;

            if (category == null)
            {
                //Not a Category - must be a subcategory
                category = await DataManager.CategoryDataSource.GetParentCategory(param);

                if (category != null)
                {
                    subCategories       = category.SubCategoryItems;
                    selectedSubCategory = subCategories.FirstOrDefault(item => item.Id == param);
                }
                else
                {
                    //error - id is not a category or subcategory
                    throw new Exception("The Parameter is not a Category or a SubCategory");
                }
            }
            else
            {
                //Populate the SubCategories + get the first SubCategory;
                subCategories       = category.SubCategoryItems;
                selectedSubCategory = subCategories.FirstOrDefault();
            }

            CategoryId = category.Id;

            //Populate the SubCategory Display Items..
            ObservableCollection <SubCategoryDisplayItem> subCategoryDisplayItems = new ObservableCollection <SubCategoryDisplayItem>();
            SubCategoryDisplayItem selectedSubCategoryDisplayItem = null;

            foreach (var subCategory in subCategories)
            {
                var sc   = new SubCategoryDisplayItem(category.Id, category.Name, subCategory);
                var prds = (await DataManager.ProductDataSource.GetProductsBySubCategoryIdAsync(subCategory.Id)).ToList();
                sc.AllProducts      = new List <Product>(prds);
                sc.FilteredProducts = new List <Product>(prds);
                subCategoryDisplayItems.Add(sc);
                if (selectedSubCategory.Id == sc.Id)
                {
                    selectedSubCategoryDisplayItem = sc;
                }
            }

            CategoryName  = category.Name;
            CategoryId    = category.Id;
            SelectedPivot = selectedSubCategoryDisplayItem;
            PivotItems    = subCategoryDisplayItems.ToList();
        }
 public HomeView(AdminPanel admnPanel, ProductSubCategory prdSubCt, List <ProductSubCategory> subPrdsCts, List <ProductCategory> prdsCts, List <FooterMod> footLst, List <StockUser> stcList) :
     base(admnPanel, prdSubCt, subPrdsCts, prdsCts)
 {
     ProductSubCat       = prdSubCt;
     SubProductsCategory = subPrdsCts;
     ProductsCategorys   = prdsCts;
     FooterList          = footLst;
     StockList           = stcList;
 }
        public async Task <ProductSubCategory> CreateProductSubCategory(ProductSubCategory productSubCategory, ProductMainCategory productMainCategory)
        {
            productSubCategory.MainCategory = productMainCategory;
            await _context.ProductSubCategories.AddAsync(productSubCategory);

            await _context.SaveChangesAsync();

            return(productSubCategory);
        }
        public async Task <Product> CreateProduct(Product product, ProductSubCategory productSubCategory)
        {
            product.SubCategory = productSubCategory;
            await _context.Products.AddAsync(product);

            await _context.SaveChangesAsync();

            return(product);
        }
Beispiel #25
0
        // POST: api/Product
        public async Task <ActionResult <ProductModel> > PostProducts([FromBody] ProductModel model)
        {
            //string userId = User.Claims.First(c => c.Type == "UserID").Value;
            //var user = await _userManager.FindByIdAsync(userId);await _context.ProductSubCategories.ToListAsync();

            /*
             *          var ProductSubCategory = new ProductSubCategory()
             *          {
             *              ProductSubCategoryID = model.ProductSubCategoryID,
             *              SubCategoryName = "Lotion"
             *          };
             */
            //ProductSubCategory addProductSubCategory = await _context.ProductSubCategories.Single(SubC => SubC.ProductSubCategoryID ==
            //model.ProductSubCategoryID);
            ProductSubCategory addProductSubCategory = await _context.ProductSubCategories.FirstOrDefaultAsync(SubC => SubC.ProductSubCategoryID ==
                                                                                                               model.ProductSubCategoryID);

            // IList<ProductSubCategory> subCategories = await _context.ProductSubCategories.Include(SubC => SubC.ProductSubCategoryID)
            //                                                                             .Where(SubC => SubC.ProductSubCategoryID == model.ProductSubCategoryID);

            var ProductSubCategoryModel = new ProductSubCategoryModel()
            {
                ProductSubCategoryID = addProductSubCategory.ProductSubCategoryID,
                SubCategoryName      = addProductSubCategory.SubCategoryName
            };
            //Convert.ToInt32()
            var Product = new Product()
            {
                Barcode              = model.Barcode,
                ProductName          = model.ProductName,
                ProductType          = model.ProductType,
                Quantity             = model.Quantity,
                Description          = model.Description,
                UnitPrice            = model.UnitPrice,
                Features             = model.Features,
                Usage                = model.Usage,
                BillingAddress       = model.BillingAddress,
                TC                   = model.TC,
                ImageUrl             = model.ImageUrl,
                Category             = model.Category,
                ProductSubCategoryID = model.ProductSubCategoryID,
                ProductSubCategory   = addProductSubCategory
            };

            try
            {
                await _context.Products.AddAsync(Product);

                await _context.SaveChangesAsync();

                return(Ok(new JsonResult("The Product was Added Successfully")));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 public static void DeleteProductSubCategory(int id)
 {
     using (EcommerceEntities entities = new EcommerceEntities())
     {
         ProductSubCategory productSubCategory = entities.ProductSubCategories.Where(entry => entry.ID == id).FirstOrDefault();
         entities.ProductSubCategories.Remove(productSubCategory);
         entities.SaveChanges();
     }
 }
Beispiel #27
0
        public ActionResult Index()
        {
            ProductSubCategory category = new ProductSubCategory();

            category.ProductSubCategoryCollection = repository.GetAll().OrderByDescending(x => x.ModifiedDate).ToList();
            IRepositoryBase <ProductCategory> repositoryCategory = new ProductCategoryRepository();

            category.ProductCategoryCollection = repositoryCategory.GetAll().ToList();
            return(View(category));
        }
 public ActionResult Edit([Bind(Include = "ProductSubCategoryID,ProductSubCategoryName,Rate,Available,DisplayOrder,Image")] ProductSubCategory productSubCategory)
 {
     if (ModelState.IsValid)
     {
         db.Entry(productSubCategory).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(productSubCategory));
 }
 public ActionResult Add(VmProductSubCategoryAdd model, HttpPostedFileBase file)
 {
     TempData["SuccessMsg"] = "";
     TempData["FailedMsg"]  = "";
     if (ModelState.IsValid)
     {
         try
         {
             if (db.ProductSubCategory.Any(a => a.ProductCategoryHeaderId == model.ProductCategoryHeaderId && a.ProductSubCategoryName == model.ProductSubCategoryName))
             {
                 TempData["FailedMsg"] = "Sub-Category Already Exist";
             }
             else
             {
                 #region Image Upload
                 var uri = Request.Url.Host;
                 System.IO.Directory.CreateDirectory(Server.MapPath("~/Images/ProductSubCategory/" + uri));
                 string path = "";
                 if (file != null)
                 {
                     string pic          = System.IO.Path.GetFileName(file.FileName);
                     string physicalPath =
                         System.IO.Path.Combine(Server.MapPath("~/Images/ProductSubCategory/" + uri), pic);
                     path = "/Images/ProductSubCategory/" + uri + "/" + pic;
                     file.SaveAs(physicalPath);
                     model.ImageUrl = path;
                 }
                 #endregion
                 var newData = new ProductSubCategory {
                     ProductCategoryHeaderId = model.ProductCategoryHeaderId,
                     ProductSubCategoryName  = model.ProductSubCategoryName,
                     ImageUrl = model.ImageUrl,
                     ProductSubCategoryHeaderId = 0
                 };
                 db.ProductSubCategory.Add(newData);
                 db.SaveChanges();
                 TempData["SuccessMsg"] = "Sub-Category Added Successfully";
                 return(RedirectToAction("Index"));
             }
         }
         catch (Exception e)
         {
             TempData["FailedMsg"] = e.Message;
         }
     }
     else
     {
         TempData["FailedMsg"] = "Failed";
     }
     ViewBag.CategoryList = db.ProductCategory.Select(s => new VmSelectList {
         Id = s.ProductCategoryHeaderId, Name = s.ProductCategoryName
     });
     return(View(model));
 }
        // Sub Categories Delete
        protected void grdSubCat_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            ProductSubCategory delsubcat = beta.ProductSubCategories.First((sc => sc.ProductSubCatID.Equals(SubcatId)));

            beta.ProductSubCategories.Remove(delsubcat);
            beta.SaveChanges();
            ShowSubCat();
            ClearData();
            GetDrpCat();
            lblSubError.Text = "SubCategories Deleted";
        }