예제 #1
0
        public IActionResult CreateSales(Sales sale)
        {
            string isoJson = JsonConvert.SerializeObject(sale);
            // {"Details":"Application started.","LogDate":"2009-02-15T00:00:00Z"}

            JsonSerializerSettings microsoftDateFormatSettings = new JsonSerializerSettings
            {
                DateFormatHandling = DateFormatHandling.MicrosoftDateFormat
            };
            string microsoftJson = JsonConvert.SerializeObject(sale, microsoftDateFormatSettings);
            // {"Details":"Application started.","LogDate":"\/Date(1234656000000)\/"}

            string javascriptJson = JsonConvert.SerializeObject(sale, new JavaScriptDateTimeConverter());

            // {"Details":"Application started.","LogDate":new Date(1234656000000)}
            try
            {
                Console.WriteLine("adding");
                // _context.Sales.Add(sale);
                _context.Sales.Add(new Sales
                {
                    Productid  = sale.Productid,
                    Customerid = sale.Customerid,
                    Storeid    = sale.Storeid,
                    Datesolde  = sale.Datesolde.Date
                });
                _context.SaveChanges();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(Json(new { Data = "Create Customer Failed", c = sale }));
            }
            return(Json(new { Data = "Customer created", c = sale }));
        }
예제 #2
0
 public JsonResult CreateCustomer(Customer customer)
 {
     try
     {
         Console.WriteLine("adding");
         _context.Customer.Add(new Customer {
             Name    = customer.Name,
             Address = customer.Address
         });
         _context.SaveChanges();
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         return(Json(new { Data = "Create Customer Failed", c = customer }));
     }
     return(Json(new { Data = "Customer created", c = customer }));
 }
예제 #3
0
 public JsonResult CreateProduct(Product product)
 {
     try
     {
         Console.WriteLine("adding");
         _context.Product.Add(new Product {
             Name  = product.Name,
             Price = product.Price
         });
         _context.SaveChanges();
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         return(Json(new { Data = "Create Product Failed", c = product }));
     }
     return(Json(new { Data = "Product created", c = product }));
 }
예제 #4
0
 public JsonResult CreateStore(Store store)
 {
     try
     {
         Console.WriteLine("adding");
         _context.Store.Add(new Store
         {
             Name    = store.Name,
             Address = store.Address
         });
         _context.SaveChanges();
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         return(Json(new { Data = "Create Customer Failed", c = store }));
     }
     return(Json(new { Data = "Customer created", c = store }));
 }