public void Update(InsertUpdateCategoryDTO entity, int id) { var category = _unitOfWork.Category.Find(c => c.Id == id).FirstOrDefault(); category.Name = entity.Name; category.ModifiedAt = DateTime.Now; _unitOfWork.Save(); }
public IActionResult Post([FromBody] InsertUpdateCategoryDTO dto) { try { _service.Insert(dto); return(Ok("Category successfully created!")); } catch (Exception e) { return(BadRequest(e.Message)); } }
public int Insert(InsertUpdateCategoryDTO entity) { var category = new Category() { Name = entity.Name, CreatedAt = DateTime.Now }; _unitOfWork.Category.Add(category); _unitOfWork.Save(); return(category.Id); }
public IActionResult Put(int id, [FromBody] InsertUpdateCategoryDTO dto) { try { _service.Update(dto, id); return(Ok("Category successfully updated")); } catch (Exception e) { Console.WriteLine(e); return(BadRequest(e.Message)); } }
public ActionResult Create(IFormCollection collection) { try { var dto = new InsertUpdateCategoryDTO() { Name = collection["Name"], }; _service.Insert(dto); return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
public ActionResult Edit(int id, IFormCollection collection) { try { var dto = new InsertUpdateCategoryDTO() { Name = collection["Name"] }; _service.Update(dto, id); return(RedirectToAction(nameof(Index))); } catch (Exception e) { Console.WriteLine(e); return(View()); } }
public void Delete(InsertUpdateCategoryDTO entity) { throw new System.NotImplementedException(); }