public IActionResult Post(Productnya pros) { var p = pros.data.attributes; _context.ProductsData.Add(p); var time = (DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0).ToLocalTime()).TotalSeconds; p.created_at = (long)time; p.updated_at = (long)time; _context.SaveChanges(); return(Ok(new { message = "success retrieve data", status = true, data = p })); }
public IActionResult Put(int id, Productnya pros) { var p = pros.data.attributes; try { var f = _context.ProductsData.Find(id); f.name = p.name; f.price = p.price; var time = (DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0).ToLocalTime()).TotalSeconds; f.updated_at = (long)time; _context.SaveChanges(); return(Ok(new { message = "success retrieve data", status = true, data = p })); } catch (Exception) { return(NotFound()); } }