public ActionResult Category(int?Id) { if (!Id.HasValue) { return(NotFound()); } var category = categoryService.GetById(Id.Value); if (category == null) { return(NotFound()); } if (!category.IsActive || category.IsDelete) { return(NotActive()); } var model = new CategoryDetailModel() { Id = category.Id, Name = category.Name }; return(View(model)); }
public ActionResult Index(String name) { var categoryName = name; var categoryServiceClient = new ServiceReference2.CategoryServiceClient(); List <CategoryDetailModel> response = new List <CategoryDetailModel>(); var listCategories = categoryServiceClient.GetCategoryByName(name); if (listCategories == null) { Session["CategoryFound"] = 0; return(View("Index")); } else { foreach (var c in listCategories) { CategoryDetailModel cTemp = new CategoryDetailModel() { CategoryId = c.CategoryId, CategoryName = c.CategoryName, Description = c.Description, Picture = c.Picture }; response.Add(cTemp); } Session["CategoryFound"] = 1; return(View("Index", response)); } }
/************************************ Details Category **************************************** * ************************************************************************************************************/ public ActionResult Details(long id) { var categoryServiceClient = new ServiceReference2.CategoryServiceClient(); var category = categoryServiceClient.GetCategoryById(id); var categoryById = new CategoryDetailModel { CategoryName = category.CategoryName, Description = category.Description, Picture = category.Picture, ExtensionData = category.ExtensionData }; return(View(categoryById)); }
public ActionResult UpdateCategory(int id) { var CategoryInfo = new CategoryDetailModel(); CategoryInfo.IsNew = false; CategoryInfo.Category = oDBContext.OfferCategories.FirstOrDefault(t => t.ID == id); ViewBag.CategoryList = oDBContext.OfferCategories.Select(x => x).ToList().Select(x => new SelectListItem { Value = x.ID.ToString(), Text = x.CategoryName.ToString() }); return(PartialView("_categoryDetailPartial", CategoryInfo)); }
public ActionResult Edit(CategoryDetailModel category) { var categoryServiceClient = new ServiceReference2.CategoryServiceClient(); CategoryDetail newCategory = new CategoryDetail() { CategoryName = category.CategoryName, Description = category.Description, Picture = category.Picture, }; newCategory.CategoryId = (long)Session["CategoryModified"]; categoryServiceClient.UpdateCategory(newCategory); Session["CategoryModified"] = -1; return(RedirectToAction("Index")); }
public ActionResult AddCategory(CategoryDetailModel category) { var categoryServiceClient = new ServiceReference2.CategoryServiceClient(); CategoryDetail newCategory = new CategoryDetail { CategoryName = category.CategoryName, Description = category.Description, Picture = category.Picture, }; if (categoryServiceClient.AddCategory(newCategory)) { return(View()); } else { return(View()); } }
public ActionResult NewCategory() { oCurrentUser = (SysUser)Session["User"]; var newCategory = new OfferCategory(); newCategory.IsActive = false; var CategoryInfo = new CategoryDetailModel(); CategoryInfo.IsNew = true; CategoryInfo.Category = newCategory; ViewBag.CategoryList = oDBContext.OfferCategories.Select(x => x).ToList().Select(x => new SelectListItem { Value = x.ID.ToString(), Text = x.CategoryName.ToString() }); return(PartialView("_categoryDetailPartial", CategoryInfo)); }
public ActionResult Index(int?Id, int page = 1) { if (!Id.HasValue) { return(HomePage()); } var category = categoryService.GetById(Id.Value); if (category == null) { return(NotFound()); } if (!category.IsActive || category.IsDelete) { return(NotFound()); } int pageSize = settingService.GetSetting("general.pagesize").IntValue; var model = new CategoryDetailModel { Name = category.Name, Posts = postService.GetActives(Id.Value).Select(x => new PostModel { Title = x.Title, PicturePath = x.PicturePath, ShortContent = x.ShortContent, CreateDate = x.CreateDate, Url = urlService.GetUrl(x.Id, Core.Enums.EntityType.Post), CommentCount = postService.GetCommentCount(x.Id), CategoryName = categoryService.GetById(x.CategoryId).Name, CategoryUrl = urlService.GetUrl(x.CategoryId, Core.Enums.EntityType.Category), ViewCount = x.ViewCount }).ToPagedList(page - 1, pageSize) }; return(View(model)); }
public ActionResult InsertCategory(CategoryDetailModel oCategoryInfo, HttpPostedFileBase ctrlCatIcon) { try { if (ModelState.IsValid) { oCurrentUser = (SysUser)Session["User"]; var uploadFileName = ""; var existCategory = oDBContext.OfferCategories.FirstOrDefault(t => t.ID == oCategoryInfo.Category.ID); if (existCategory == null) { OfferCategory oOfferCategory = oCategoryInfo.Category; oOfferCategory.IsActive = true; if (ctrlCatIcon != null) { uploadFileName = DateTime.Now.ToString("yyddMMhhmmssfff") + "_" + Path.GetFileName(ctrlCatIcon.FileName).Replace(" ", "").ToLower().Trim(); oOfferCategory.CategoryIcon = postImagePath + uploadFileName; ctrlCatIcon.SaveAs(Path.Combine(Server.MapPath(postImagePath), uploadFileName)); } oOfferCategory.CreatedBy = oCurrentUser.ID; oOfferCategory.CreatedOn = DateTime.Now; oDBContext.OfferCategories.Add(oOfferCategory); oDBContext.SaveChanges(); TempData["SuccessMsg"] = "Data Saved Successfully"; } else { TempData["ErrorMsg"] = "Data already Exists!!!"; } } } catch (Exception ex) { TempData["ErrorMsg"] = "Error Occured Due to " + ExceptionMsg(ex); } return(RedirectToAction("Index")); }
public ActionResult UpdateCategory(CategoryDetailModel oCategoryInfo, string chkIsActive, HttpPostedFileBase ctrlCatIcon) { try { if (ModelState.IsValid) { oCurrentUser = (SysUser)Session["User"]; var uploadFileName = ""; var existCategory = oDBContext.OfferCategories.FirstOrDefault(t => t.ID == oCategoryInfo.Category.ID); if (existCategory != null) { existCategory.CategoryName = oCategoryInfo.Category.CategoryName; if (ctrlCatIcon != null) { uploadFileName = DateTime.Now.ToString("yyddMMhhmmssfff") + "_" + Path.GetFileName(ctrlCatIcon.FileName).Replace(" ", "").ToLower().Trim(); existCategory.CategoryIcon = postImagePath + uploadFileName; ctrlCatIcon.SaveAs(Path.Combine(Server.MapPath(postImagePath), uploadFileName)); } existCategory.IsActive = (!string.IsNullOrEmpty(chkIsActive) && chkIsActive.Contains("on")) ? true : false; existCategory.ModifiedBy = oCurrentUser.ID; existCategory.ModifiedOn = DateTime.Now; oDBContext.SaveChanges(); TempData["SuccessMsg"] = "Data Update Successfully"; } else { TempData["ErrorMsg"] = "Data Not Found!!!"; } } } catch (Exception ex) { TempData["ErrorMsg"] = "Error Occured Due to " + ExceptionMsg(ex); } return(RedirectToAction("Index")); }
/************************************ Adding Category **************************************** **************************************************************************************************************/ public ActionResult AddCategory() { var category = new CategoryDetailModel(); return(View(category)); }
protected override async Task OnInitializedAsync() { category = await Client.GetCategoryDetail(_CategoryId); }