public async Task <IActionResult> Put([FromBody] TeaCategory jslot) { var updateSlot = _context.TeaCategorys.FirstOrDefault(c => c.Id == jslot.Id); if (ModelState.IsValid) { updateSlot.Id = jslot.Id; updateSlot.CategoryName = jslot.CategoryName; updateSlot.SlotNo = jslot.SlotNo; updateSlot.SubSlot = jslot.SubSlot; _context.TeaCategorys.Attach(updateSlot); _context.Entry(updateSlot).State = System.Data.Entity.EntityState.Modified; _logger.LogInformation((int)6, "update category from database"); await _context.SaveChangesAsync(); } return(Json("done")); }
public IActionResult Category(TeaCategory category) { ViewData["Title"] = "Herbaty - " + category; var teas = _teaRepository.GetTeasByCategory(category); var model = _mapper.Map <IEnumerable <Tea>, IEnumerable <TeaViewModel> >(teas); return(View("Index", model)); }
public async Task <IActionResult> Post([FromBody] TeaCategory slot) { if (ModelState.IsValid) { _context.TeaCategorys.Add(slot); _logger.LogInformation((int)1, "Add category to database"); await _context.SaveChangesAsync(); } return(Json("done")); }
public JsonResult EachCategory(int id) { TeaCategory result = new TeaCategory(); if (ModelState.IsValid) { result = AllCategorys().FirstOrDefault(c => c.Id == id); } return(Json(result)); }
public IActionResult CategoryCreate([FromBodyAttribute] TeaCategory teaCategory) { if (ModelState.IsValid) { _context.TeaCategorys.Add(teaCategory); _context.SaveChanges(); } return(Json("done")); }
public async Task <JsonResult> Get(int id) { TeaCategory result = new TeaCategory(); if (ModelState.IsValid) { result = _context.TeaCategorys.FirstOrDefault(c => c.Id == id); _logger.LogInformation((int)4, "get each category from database"); } return(Json(result)); }
public IActionResult UpdateCategory([Microsoft.AspNetCore.Mvc.FromBodyAttribute] TeaCategory jslot) { if (ModelState.IsValid) { StringContent content = new StringContent(JsonConvert.SerializeObject(jslot), Encoding.UTF8, "application/json"); var result = client().PutAsync("api/Categorys", content).Result; _logger.LogInformation((int)1, "Add tea items to database"); } return(Json("done")); }
public IActionResult CategoryCreate([Microsoft.AspNetCore.Mvc.FromBodyAttribute] TeaCategory teaCategory) { //if (ModelState.IsValid) //{ // _context.TeaCategorys.Add(teaCategory); // _context.SaveChanges(); //} if (ModelState.IsValid) { StringContent content = new StringContent(JsonConvert.SerializeObject(teaCategory), Encoding.UTF8, "application/json"); var result = client().PostAsync("api/Categorys", content).Result; _logger.LogInformation((int)1, "Add category to database"); } return(Json("done")); }
public IActionResult UpdateCategory([FromBodyAttribute] TeaCategory jslot) { var updateSlot = _context.TeaCategorys.FirstOrDefault(c => c.Id == jslot.Id); if (ModelState.IsValid) { updateSlot.Id = jslot.Id; updateSlot.CategoryName = jslot.CategoryName; updateSlot.SubSlot = jslot.SubSlot; updateSlot.SlotNo = jslot.SlotNo; _context.TeaCategorys.Attach(updateSlot); _context.Entry(updateSlot).State = System.Data.Entity.EntityState.Modified; _context.SaveChanges(); } return(Json("done")); }
public IEnumerable <Tea> GetTeasByCategory(TeaCategory category) { return(_context.Teas.Where(t => t.Category == category).Where(t => t.IsActive)); }