コード例 #1
0
        public IActionResult Post([FromBody] CreatePizzaDTO createPizzaDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var pizzaDetail = _pizzaService.Create(createPizzaDTO);

            return(StatusCode(201, pizzaDetail));
        }
コード例 #2
0
        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();
        }
コード例 #3
0
        public async Task <ActionResult <PizzaDto> > PostPizza([FromBody] CreatePizzaModel pizza)
        {
            var newPizza = await _pizzaService.Create(pizza);

            return(CreatedAtAction(nameof(GetById), new { id = newPizza.Id }, newPizza));
        }