コード例 #1
0
        public IActionResult Post(RequestProduct request)
        {
            var products = request.data.attributes;
            var date     = (DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0).ToLocalTime()).TotalSeconds;

            products.created_at = (long)date;
            products.updated_at = (long)date;
            _context.products.Add(products);
            _context.SaveChanges();
            return(Ok(new { message = "success add data", status = true, data = products }));
        }
コード例 #2
0
        public IActionResult PutById(int id, RequestProduct request)
        {
            var products = request.data.attributes;

            try
            {
                var result = _context.products.First(x => x.id == id);
                result.name       = products.name;
                result.price      = products.price;
                result.updated_at = (long)(DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0).ToLocalTime()).TotalSeconds;
                _context.SaveChanges();
                return(Ok(new { message = "success update data", status = true, data = result }));
            }
            catch (Exception)
            {
                return(NotFound());
            }
        }