protected void CreateHeader(int categoryId, string title = "") { TblCategory category = LIST_CATEGORY.FirstOrDefault(o => o.CategoryId == categoryId); if (category == null) { category = LIST_CATEGORY.First(o => o.CategoryId == 1); } mymodel.ads1 = LIST_ADS[0].Ads; mymodel.ads2 = LIST_ADS[1].Ads; mymodel.TitLe = title != "" ? title : category.Title; mymodel.Description = category.Description; mymodel.Keywords = category.Keywords; mymodel.CategoryId = categoryId; List <TblNews> LsNewRecent = LIST_NEWS; if (categoryId != 0) { LsNewRecent = LsNewRecent.Where(o => o.CategoryId == categoryId).OrderByDescending(o => o.DateNews).Take(5).ToList(); } mymodel.LsNewRecent = LsNewRecent; }
public ActionResult CreateOrEdit(Category category) { if (!ModelState.IsValid) { return(View(nameof(Edit), category)); } TblCategory dbCategory = _context.TblCategory.Find(category.CategoryId); if (dbCategory == null) { dbCategory = new TblCategory(); } dbCategory.Description = category.Description; dbCategory.Name = category.Name; if (!TryValidateModel(dbCategory)) { return(View(nameof(Edit), category)); } _context.TblCategory.AddOrUpdate(dbCategory); _context.SaveChanges(); TempData["message"] = "Category Updated/Created!"; TempData["messageColorClass"] = "alert-success"; return(RedirectToAction(nameof(Show), new { id = dbCategory.CategoryId })); }
/// <summary> /// Lấy ra danh sách danh mục theo CategoryCode /// CreatedBy: Cuongpv1 /// CreatedDate: 23/05/2019 /// </summary> /// <param name="CategoryCode"></param> /// <returns></returns> public object GetCategoryByCateCode(string CategoryCode) { try { TblCategory category = db.TblCategory.Where(v => v.IsDelete == false && v.CategoryCode == CategoryCode).FirstOrDefault(); TblCategoryGroup categroup = db.TblCategoryGroup.Where(v => v.IsDelete == false && v.CategoryCode == CategoryCode).FirstOrDefault(); ListCategory objCategory = new ListCategory(); if (category != null) { objCategory.CategoryCode = category.CategoryCode; objCategory.CategoryTypeCode = category.CategoryTypeCode; objCategory.CategoryName = category.CategoryName; objCategory.CategoryDescription = category.CategoryDescription; objCategory.children = GetAllChildCategory(category.CategoryCode); } else { objCategory.CategoryCode = categroup.CategoryCode; objCategory.CategoryTypeCode = categroup.CategoryTypeCode; objCategory.CategoryName = categroup.CategoryGroupName; objCategory.CategoryDescription = categroup.CategoryDescription; objCategory.children = GetAllChildCategory(categroup.CategoryCode); } return(objCategory); } catch (Exception ex) { return(new { code = 500, messsage = ex.Message }); } }
protected override void Seed(Models.AppDbContext context) { // This method will be called after migrating to the latest version. for (int i = 1; i <= 10; i++) { var category = new TblCategory { Name = $"DAW{i}", Description = "A place to discuss DAW project", CategoryId = i }; context.TblCategory.AddOrUpdate(category); context.SaveChanges(); var post = new TblPost { CategoryId = category.CategoryId, Title = $"project {i} progress update", Content = $"Started The project {i}", CreatedDate = DateTime.Now, PostId = i }; context.TblPost.AddOrUpdate(post); context.SaveChanges(); } // You can use the DbSet<T>.AddOrUpdate() helper extension method // to avoid creating duplicate seed data. }
public object checkCategoryCode(string categoryCode) { ErrorObject response = new ErrorObject(); object objCate = new TblCategory(); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } object deleteCateCode = _categoryRepository.checkCategoryCode(categoryCode); int code = Convert.ToInt32(deleteCateCode.GetType().GetProperty(CategoryConstant.Code).GetValue(deleteCateCode, null)); string CateCode = deleteCateCode.GetType().GetProperty(CategoryConstant.CategoryCode).GetValue(deleteCateCode, null).ToString(); if (code == 1) { response.message = CategoryConstant.MessageValidate; return(StatusCode(200, response)); } else if (code == 0) { response.title = CategoryConstant.titleDelete; response.entityName = CategoryConstant.entityNameDelete; response.errorKey = CategoryConstant.errorKeyDelete; response.status = CategoryConstant.statusError; response.message = CategoryConstant.MessageDelete; return(StatusCode(400, response)); } else { return(StatusCode(400)); } }
public ActionResult CategoryUpdate(TblCategory p) { var category = db.TblCategory.Find(p.ID); category.Name = p.Name; db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult DeleteConfirmed(int id) { TblCategory tblCategory = db.TblCategories.Find(id); db.TblCategories.Remove(tblCategory); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult UpdateCategory(TblCategory tblCategory) { var category = DbStockEntities.TblCategory.Find(tblCategory.CategoryId); //Güncellenmek istenen kategory Id değerine göre bulundu.Ve category değişkenine aktarıldı. category.CategoryName = tblCategory.CategoryName; //Var olan kategori alanında yapılan güncelleme oluşturulan değişken değerine atandı. DbStockEntities.SaveChanges(); //Veri tabanı değişiklikleri kaydedildi. return(RedirectToAction("Index")); //Index Viewine yönlendirildi. }
public object AddCategory([FromBody] CategoryChildren tblCategory) { ErrorObject response = new ErrorObject(); ResponseMessage rm = new ResponseMessage(); FieldErrors error = new FieldErrors(); object objCate = new TblCategory(); string userName = User.Claims.FirstOrDefault().Value; tblCategory.CreateBy = userName; if (string.IsNullOrEmpty(tblCategory.CategoryName)) { List <FieldErrors> lsterror = new List <FieldErrors>(); if (string.IsNullOrEmpty(tblCategory.CategoryName)) { error.objectName = CategoryConstant.TypeCategory; error.field = CategoryConstant.entityName; error.message = CategoryConstant.Message; lsterror.Add(error); } rm.Title = CategoryConstant.Title; rm.Message = CategoryConstant.MessageError; rm.Status = CategoryConstant.statusError; var field = new { fieldErrors = lsterror }; rm.fieldError = field; return(StatusCode(400, rm)); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } object objCategory = _categoryRepository.AddCategory(tblCategory); int code = Convert.ToInt32(objCategory.GetType().GetProperty(CategoryConstant.Code).GetValue(objCategory, null)); string CateCode = objCategory.GetType().GetProperty(CategoryConstant.CategoryCode).GetValue(objCategory, null).ToString(); if (code == 0) { response.title = CategoryConstant.titleDuplicate; response.entityName = CategoryConstant.entityName; response.errorKey = CategoryConstant.errorKey; response.status = CategoryConstant.statusError; response.message = CategoryConstant.MessageDulicateCategoryName; return(StatusCode(400, response)); } else if (code == 1) { if (!string.IsNullOrEmpty(CateCode)) { objCate = _categoryRepository.GetObjectCategory(CateCode); } var responeNew = new { TblCategory = objCate }; return(StatusCode(201, responeNew)); } else { return(StatusCode(400)); } }
public IActionResult Edit(int id, [Bind("CategoryId,CategoryName,CategoryDescription,CategoryIsExpenditure")] TblCategory category) { if (ModelState.IsValid) { _cateService.UpdateCategory(category); return(RedirectToAction(nameof(Index))); } return(View(category)); }
public ActionResult Edit([Bind(Include = "CategoryId,CategoryName,Description,Subcategory")] TblCategory tblCategory) { if (ModelState.IsValid) { db.Entry(tblCategory).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tblCategory)); }
public ActionResult UpdateCategory(TblCategory tbl) { if (ModelState.IsValid) { _context.TblCategory.Update(tbl); _context.SaveChanges(); return(RedirectToAction("Category")); } return(View("Category")); }
public IActionResult Category(TblCategory C) { C.CreatedDate = DateTime.Now.ToString("dd/MM/yyyy/hh/mm/ss"); C.ModifyDate = DateTime.Now.ToString("dd/MM/yyyy/hh/mm/ss"); context.TblCategory.Add(C); context.SaveChanges(); ViewBag.Message = "Your Desired Category Added Successfully"; return(View()); //return RedirectToAction("Category"); }
public ActionResult Create([Bind(Include = "CategoryId,CategoryName,Description,Subcategory")] TblCategory tblCategory) { if (ModelState.IsValid) { db.TblCategories.Add(tblCategory); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tblCategory)); }
public IActionResult Index(string urlFriendly) { // Get data header page TblCategory tblCategory = _context.TblCategory.Where(o => o.UrlFriendly == urlFriendly).First(); CreateHeader(tblCategory.CategoryId); List <TblNews> lsTblNews = _context.TblNews.Where(o => o.CategoryId == tblCategory.CategoryId).ToList(); mymodel.CategoryName = tblCategory.CategoryName; mymodel.LsNew = lsTblNews; return(View(mymodel)); }
public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } TblCategory tblCategory = db.TblCategories.Find(id); if (tblCategory == null) { return(HttpNotFound()); } return(View(tblCategory)); }
public async Task <IActionResult> Create([FromBody] TblCategory category) { try { AVSContext avsDBContext = new AVSContext(); avsDBContext.TblCategory.Add(category); avsDBContext.SaveChanges(); return(Ok(category)); } catch (Exception ex) { return(BadRequest("Invalid input data!")); } }
/// <summary> /// xóa danh mục con /// CreatedBy: Cuongpv1 /// CreatedDate: 23/05/2019 /// </summary> /// <param name="lstCategoryCode"></param> public void DeleteCategoryChild(List <ObjectDeleteCategoryCode> lstCategoryCode) { List <TblCategory> lstcate = new List <TblCategory>(); foreach (ObjectDeleteCategoryCode item in lstCategoryCode) { TblCategory deleteCatgory = db.TblCategory.Where(v => v.CategoryCode == item.CategoryCode && v.IsDelete == false).FirstOrDefault(); if (deleteCatgory != null) { lstcate.Add(deleteCatgory); } } db.TblCategory.RemoveRange(lstcate); db.SaveChanges(); }
public ActionResult DeleteConfirmed([Bind(Include = "CategoryId,CategoryName,Description")] TblCategory tblCategory) { HttpClient cl = new HttpClient(); cl.BaseAddress = new Uri("http://localhost:5383/Api/Categories/"); cl.DefaultRequestHeaders.Accept.Clear(); cl.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); var resp = cl.DeleteAsync("" + tblCategory.CategoryId).Result; if (resp.IsSuccessStatusCode) { return(RedirectToAction("Index")); } else { return(View()); } }
public async Task <IActionResult> EditCategory(TblCategory category) { if (category == null) { return(NotFound()); } var categoryFromDb = _db.TblCategory.Where(x => x.Id == category.Id).FirstOrDefault(); categoryFromDb.CategoryName = category.CategoryName; categoryFromDb.ModifiedDate = DateTime.Now; categoryFromDb.ParentCateId = category.ParentCateId; categoryFromDb.Status = category.Status; var result = await _db.SaveChangesAsync(); if (result > 0) { return(RedirectToAction(nameof(Category))); } return(null); }
public bool AddCategory(TblCategory category) { try { var isCateogryAdded = _context.Add(category); _context.SaveChanges(); if (isCateogryAdded.State.ToString().Equals("Added")) { return(true); } else { return(false); } } catch (Exception Ex) { return(false); } }
public bool UpdateCategory(TblCategory category) { try { var isCategoryUpdated = _context.Update(category); _context.SaveChanges(); if (isCategoryUpdated.State.ToString().Equals("Modified")) { return(true); } else { return(false); } } catch (Exception Ex) { return(false); } }
public ActionResult Show(int id) { TblCategory category = _context.TblCategory .Include(c => c.TblPost) .FirstOrDefault(c => c.CategoryId == id); List <PostListItem> categoryPosts = category.TblPost.Select(p => new PostListItem { PostId = p.PostId, Title = p.Title, Content = p.Content }).ToList(); var model = new Category { Name = category.Name, CategoryId = category.CategoryId, Description = category.Description, CategoryPosts = categoryPosts }; return(View(model)); }
public ActionResult Edit([Bind(Include = "CategoryId,CategoryName,Description")] TblCategory tblCategory) { if (ModelState.IsValid) { HttpClient cl = new HttpClient(); cl.BaseAddress = new Uri("http://localhost:5383/Api/Categories/"); cl.DefaultRequestHeaders.Accept.Clear(); cl.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); string json = JsonConvert.SerializeObject(tblCategory); StringContent content = new StringContent(json, Encoding.UTF8, "application/json"); var resp = cl.PutAsync("" + tblCategory.CategoryId, content).Result; if (resp.IsSuccessStatusCode) { return(RedirectToAction("Index")); } else { return(RedirectToAction("Edit", tblCategory.CategoryId)); } } return(View(tblCategory)); }
public ActionResult Post([FromBody] TblCategory category) { CategoryBl.Add(category); return(new JsonResult("Success")); }
public ActionResult AddCategory(TblCategory tbl) { _context.TblCategory.Add(tbl); _context.SaveChanges(); return(RedirectToAction("Category")); }
private void Init() { myCategory = new TblCategory(); //myDataTable = myCategory.SelectAll(); }
public bool AddCategory(TblCategory category) => _cateRepo.AddCategory(category);
public ActionResult CategoryAdd(TblCategory p) { db.TblCategory.Add(p); db.SaveChanges(); return(RedirectToAction("Index")); }
public bool UpdateCategory(TblCategory category) => _cateRepo.UpdateCategory(category);