public void Add(OrderAddVM model) { if (ModelState.IsValid) { OrderService.Add(model); } }
public ActionResult Add(OrderAddVM model) { if (ModelState.IsValid) { OrderService.Add(model); return(RedirectToAction("Index")); } return(View(model)); }
public IActionResult Create([FromBody] OrderAddVM model) { if (!ModelState.IsValid) { var errors = CustomValidator.GetErrorsByModel(ModelState); return(BadRequest(errors)); } { Order m = new Order { CarId = model.Car.Id, Price = float.Parse(model.Car.Price.ToString()), ClientId = model.Client.Id, Date = model.Date }; _context.Orders.Add(m); _context.SaveChanges(); return(Ok("Дані добалено")); } }
public string Create(OrderAddVM name) { var http = (HttpWebRequest)WebRequest.Create(new Uri(_url)); http.Accept = "application/json"; http.ContentType = "application/json"; http.Method = "POST"; string parsedContent = JsonConvert.SerializeObject(name); UTF8Encoding encoding = new UTF8Encoding(); Byte[] bytes = encoding.GetBytes(parsedContent); Stream newStream = http.GetRequestStream(); newStream.Write(bytes, 0, bytes.Length); newStream.Close(); var response = http.GetResponse(); var stream = response.GetResponseStream(); var sr = new StreamReader(stream); var content = sr.ReadToEnd(); return(content); }
public Task <string> CreateAsync(OrderAddVM filter) { return(Task.Run(() => Create(filter))); }