public ReturnModel updatesubcategory(updateSubcategorymodel updatesubcategory)
        {
            ReturnModel retModel = new ReturnModel();
            var         Data     = _dbcontext.subCategory.FirstOrDefault(x => x.subcategoryName.ToLower().Equals(updatesubcategory.subcategoryName.ToLower()));

            if (Data != null)
            {
                Data.subcategoryName = updatesubcategory.subcategoryName;
                Data.categoryId      = updatesubcategory.categoryId;
                Data.IsUpdated       = true;
                Data.UpdatedDateTime = DateTime.UtcNow;
                _dbcontext.subCategory.Update(Data);
                var Isupdated = _dbcontext.SaveChanges();
                if (Isupdated == 1)
                {
                    subCategory subproductcategory = new subCategory
                    {
                        subcategoryName = updatesubcategory.subcategoryName,
                        categoryId      = updatesubcategory.categoryId
                    };
                    retModel.message    = "Successfully update product";
                    retModel.statusCode = HttpStatusCode.OK;
                }
                else
                {
                    retModel.message    = "can't update product";
                    retModel.statusCode = HttpStatusCode.OK;
                }
            }
            return(retModel);
        }
示例#2
0
        private static List <subCategory> getSubcategory(string href)
        {
            List <subCategory> List = new List <subCategory>();

            try
            {
                var readHtml = new HtmlDocument();
                readHtml.LoadHtml(getResponse(href));
                var list = readHtml.QuerySelectorAll(_cat.subcategory.selector);
                foreach (var sub in list)
                {
                    var data = new subCategory();
                    data.title = sub.QuerySelector(_cat.subcategory.title).InnerText;
                    data.href  = baseURL + sub.Attributes["href"].Value;
                    //data.photo = sub.QuerySelector(_cat.subcategory.photo).Attributes["src"].Value;
                    data.meta    = sub.QuerySelector(_cat.subcategory.meta).InnerText;
                    data.article = getArticle(data.href);
                    List.Add(data);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(List);
        }
        public ActionResult DeleteConfirmed(int id)
        {
            subCategory subCategory = db.subCategory.Find(id);

            db.subCategory.Remove(subCategory);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
示例#4
0
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            subCategory subCategory = await db.subCategories.FindAsync(id);

            db.subCategories.Remove(subCategory);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "Id,CategoryId,name")] subCategory subCategory)
 {
     if (ModelState.IsValid)
     {
         db.Entry(subCategory).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CategoryId = new SelectList(db.categories, "Id", "name", subCategory.CategoryId);
     return(View(subCategory));
 }
示例#6
0
        public async Task <ActionResult> Edit([Bind(Include = "categoryID,scid,name,description")] subCategory subCategory)
        {
            if (ModelState.IsValid)
            {
                db.Entry(subCategory).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewBag.categoryID = new SelectList(db.categories, "cid", "name", subCategory.categoryID);
            return(View(subCategory));
        }
示例#7
0
        public async Task <IActionResult> Edit(int id)
        {
            subCategory requiredrow = await db.SubCategories.FindAsync(id);

            List <mainCategory> maincategories = await db.MainCategories.ToListAsync();

            SelectList maincategoriesforddl = new SelectList(maincategories, "mainCategoryId", "mainCategoryName", requiredrow.mainCategoryId);

            ViewBag.categories = maincategoriesforddl;

            return(View(requiredrow));
        }
示例#8
0
        public ActionResult DeleteConfirmed(int id)
        {
            if (Session["email"] == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            subCategory subCategory = db.subCategories.Find(id);

            db.subCategories.Remove(subCategory);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public ActionResult Create([Bind(Include = "Id,CategoryId,name")] subCategory subCategory)
        {
            if (ModelState.IsValid)
            {
                db.subCategory.Add(subCategory);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CategoryId = new SelectList(db.categories, "Id", "name", subCategory.CategoryId);
            return(View(subCategory));
        }
示例#10
0
        // GET: subCategories/Details/5
        public async Task <ActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            subCategory subCategory = await db.subCategories.FindAsync(id);

            if (subCategory == null)
            {
                return(HttpNotFound());
            }
            return(View(subCategory));
        }
        // GET: subCategories/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            subCategory subCategory = db.subCategory.Find(id);

            if (subCategory == null)
            {
                return(HttpNotFound());
            }
            return(View(subCategory));
        }
示例#12
0
        public async Task <IActionResult> Edit(int id, subCategory newsubcategory, IFormFile subcategoryphoto)
        {
            if (ModelState.IsValid)
            {
                if (subcategoryphoto != null)
                {
                    string wwwrootpath  = webhostenviroment.WebRootPath;
                    string photoname    = $"{Guid.NewGuid().ToString()}_{subcategoryphoto.FileName}";
                    string requiredpath = $"{wwwrootpath}/photos/{photoname}";
                    using (var fileStream = new FileStream(requiredpath, FileMode.Create))
                    {
                        await subcategoryphoto.CopyToAsync(fileStream);
                    }

                    subCategory requiredrow = await db.SubCategories.FindAsync(id);

                    if (requiredrow.subCategoryPhoto != null)
                    {
                        string oldphotoname = requiredrow.subCategoryPhoto.ToString();
                        string oldpath      = $"{wwwrootpath}/photos/{oldphotoname}";
                        if (System.IO.File.Exists(oldpath))
                        {
                            System.IO.File.Delete(oldpath);
                        }
                    }

                    requiredrow.subCategoryName  = newsubcategory.subCategoryName;
                    requiredrow.subCategoryPhoto = photoname;
                    requiredrow.mainCategoryId   = newsubcategory.mainCategoryId;
                    await db.SaveChangesAsync();

                    return(RedirectToAction("Index"));
                }
                else
                {
                    subCategory requiredrow = await db.SubCategories.FindAsync(id);

                    requiredrow.subCategoryName = newsubcategory.subCategoryName;
                    requiredrow.mainCategoryId  = newsubcategory.mainCategoryId;
                    await db.SaveChangesAsync();

                    return(RedirectToAction("Index"));
                }
            }
            else
            {
                return(RedirectToAction("Edit"));
            }
        }
        // GET: subCategories/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            subCategory subCategory = db.subCategory.Find(id);

            if (subCategory == null)
            {
                return(HttpNotFound());
            }
            ViewBag.CategoryId = new SelectList(db.categories, "Id", "name", subCategory.CategoryId);
            return(View(subCategory));
        }
示例#14
0
 public ActionResult Edit([Bind(Include = "id,label,secondaryCategory,isActive,createdAT")] subCategory subCategory)
 {
     if (Session["email"] == null)
     {
         return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
     }
     if (ModelState.IsValid)
     {
         db.Entry(subCategory).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.secondaryCategory = new SelectList(db.secondaryCategories, "id", "label", subCategory.secondaryCategory);
     return(View(subCategory));
 }
示例#15
0
        // GET: subCategories/Edit/5
        public async Task <ActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            subCategory subCategory = await db.subCategories.FindAsync(id);

            if (subCategory == null)
            {
                return(HttpNotFound());
            }
            ViewBag.categoryID = new SelectList(db.categories, "cid", "name", subCategory.categoryID);
            return(View(subCategory));
        }
        public ReturnModel subcategorymodels(addSubcategorymodelcs details)
        {
            ReturnModel retModel = new ReturnModel();

            try
            {
                var isExist = _dbcontext.subCategory.FirstOrDefault(x => x.subcategoryName.ToLower().Equals(details.subcategoryName.ToLower()));
                if (isExist != null)
                {
                    retModel.message    = "subCategory Already Exists";
                    retModel.statusCode = HttpStatusCode.BadRequest;
                }
                else
                {
                    subCategory subcategoryproduct = new subCategory
                    {
                        subcategoryName = details.subcategoryName,
                        categoryId      = details.categoryId,
                        IsActive        = true,
                        IsDeleted       = false,
                        IsUpdated       = false,
                        CreateDateTime  = DateTime.UtcNow,
                        DeletedDateTime = null,
                        UpdatedDateTime = null
                    };
                    _dbcontext.subCategory.Add(subcategoryproduct);
                    var isSaved = _dbcontext.SaveChanges();
                    if (isSaved > 0)
                    {
                        retModel.message    = "Successfully Added New Super Admin";
                        retModel.statusCode = HttpStatusCode.OK;
                    }
                    else
                    {
                        retModel.message    = "Can't add due to technical error";
                        retModel.statusCode = HttpStatusCode.InternalServerError;
                    }
                }
            }
            catch (Exception ex)
            {
                retModel.message    = ex.Message.ToString();
                retModel.statusCode = HttpStatusCode.InternalServerError;
            }
            return(retModel);
        }
示例#17
0
        // GET: subCategories/Delete/5
        public ActionResult Delete(int?id)
        {
            if (Session["email"] == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            subCategory subCategory = db.subCategories.Find(id);

            if (subCategory == null)
            {
                return(HttpNotFound());
            }
            return(View(subCategory));
        }
示例#18
0
        // GET: subCategories/Edit/5
        public ActionResult Edit(int?id)
        {
            if (Session["email"] == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            subCategory subCategory = db.subCategories.Find(id);

            if (subCategory == null)
            {
                return(HttpNotFound());
            }
            ViewBag.secondaryCategory = new SelectList(db.secondaryCategories, "id", "label", subCategory.secondaryCategory);
            return(View(subCategory));
        }
示例#19
0
        //DeleteAction
        public async Task <IActionResult> Delete(int id)
        {
            subCategory requiredrow = await db.SubCategories.FindAsync(id);

            string wwwrootpath = webhostenviroment.WebRootPath;

            if (requiredrow.subCategoryPhoto != null)
            {
                string oldphotoname = requiredrow.subCategoryPhoto.ToString();
                string oldpath      = $"{wwwrootpath}/photos/{oldphotoname}";
                if (System.IO.File.Exists(oldpath))
                {
                    System.IO.File.Delete(oldpath);
                }
            }

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

            return(RedirectToAction("Index"));
        }
示例#20
0
        public async Task <IActionResult> Create(subCategory newsubcategory, IFormFile subcategoryphoto)
        {
            if (ModelState.IsValid)
            {
                if (subcategoryphoto != null)
                {
                    string wwwrootpath  = webhostenviroment.WebRootPath;
                    string photoname    = $"{Guid.NewGuid().ToString()}_{subcategoryphoto.FileName}";
                    string requiredpath = $"{wwwrootpath}/photos/{photoname}";
                    using (var fileStream = new FileStream(requiredpath, FileMode.Create))
                    {
                        await subcategoryphoto.CopyToAsync(fileStream);
                    }

                    subCategory newsubcategoryobject = new subCategory {
                        subCategoryName = newsubcategory.subCategoryName, subCategoryPhoto = photoname, mainCategoryId = newsubcategory.mainCategoryId
                    };
                    db.SubCategories.Add(newsubcategoryobject);
                    db.SaveChanges();

                    return(RedirectToAction("Index"));
                }
                else
                {
                    subCategory newsubcategoryobject = new subCategory {
                        subCategoryName = newsubcategory.subCategoryName, MainCategory = newsubcategory.MainCategory
                    };
                    db.SubCategories.Add(newsubcategoryobject);
                    db.SaveChanges();

                    return(RedirectToAction("Index"));
                }
            }
            else
            {
                return(RedirectToAction("Create"));
            }
        }