public IActionResult Put(int id, Merch m) { var merchs = m.data.attributes; try { var g = _context.Merchants.Find(id); g.name = merchs.name; g.image = merchs.image; g.address = merchs.address; g.rating = merchs.rating; var time = (DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0).ToLocalTime()).TotalSeconds; g.updated_at = (long)time; _context.SaveChanges(); var y = new Merchant { id = g.id, name = merchs.name, image = merchs.image, address = merchs.address, rating = merchs.rating, created_at = g.created_at, updated_at = g.updated_at }; return(Ok(new { message = "success retrieve data", status = true, data = y })); } catch (Exception) { return(NotFound()); } }
public IActionResult Post(Merch m) { var merchs = m.data.attributes; _context.Merchants.Add(merchs); var time = (DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0).ToLocalTime()).TotalSeconds; merchs.created_at = (long)time; merchs.updated_at = (long)time; _context.SaveChanges(); return(Ok(new { message = "success retrieve data", status = true, data = merchs })); }