public IActionResult Post([FromBody] CreatePizzaDTO createPizzaDTO) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var pizzaDetail = _pizzaService.Create(createPizzaDTO); return(StatusCode(201, pizzaDetail)); }
private void Import(object obj) { XmlSerializer xs = new XmlSerializer(typeof(ObservableCollection <PizzaViewModel>)); FileStream fs; IEnumerable <PizzaViewModel> list; using (fs = new FileStream("export.dat", FileMode.Open, FileAccess.Read, FileShare.Read)) { list = (IEnumerable <PizzaViewModel>)xs.Deserialize(fs); } foreach (var pizza in list) { try { pizzaService.Create(pizza); } catch (Exception e) { MessageBox.Show(e.Message); NLog.LogManager.GetCurrentClassLogger().Error(e, "Ошибка импорта пиццы"); } } RefreshPizzas(); }
public async Task <ActionResult <PizzaDto> > PostPizza([FromBody] CreatePizzaModel pizza) { var newPizza = await _pizzaService.Create(pizza); return(CreatedAtAction(nameof(GetById), new { id = newPizza.Id }, newPizza)); }