Exemple #1
0
 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));
 }
Exemple #3
0
 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("Дані добалено"));
     }
 }
Exemple #4
0
        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);
        }
Exemple #5
0
 public Task <string> CreateAsync(OrderAddVM filter)
 {
     return(Task.Run(() => Create(filter)));
 }