Exemplo n.º 1
0
        public async Task <ActionResult <bool> > CreateReciept(string userName, Reciept reciept)
        {
            var userByUserName = await _userService.GetUserByUserName(userName);

            if (userByUserName == null)
            {
                return(NotFound($"User not found for userName: {userName}"));
            }

            if (!ModelState.IsValid || userName != reciept.UserName)
            {
                return(BadRequest(ModelState));
            }
            reciept.UserName = userName;

            var createdReciept = await _recieptService.CreateReciept(reciept);

            return(Created("Reciept created successfully", createdReciept));
        }
Exemplo n.º 2
0
        private void F_Save_Click(object sender, EventArgs e)
        {
            if (CheckForm())
            {
                /* if (string.IsNullOrEmpty(.Text))
                 * {
                 *   MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 *   return;
                 * }
                 * if (string.IsNullOrEmpty(FCakePrice.Text))
                 * {
                 *   MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 *   return;
                 * }
                 * if (CakeIngredients == null || CakeIngredients.Count == 0)
                 * {
                 *   MessageBox.Show("Заполните компоненты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 *   return;
                 * }*/
                try
                {
                    List <ProductWaybillBM> ProductWaybillBM = new List <ProductWaybillBM>();
                    for (int i = 0; i < ProductWaybills.Count; ++i)
                    {
                        ProductWaybillBM.Add(new ProductWaybillBM
                        {
                            Id        = ProductWaybills[i].Id,
                            ProductId = ProductWaybills[i].ProductId,
                            WaybillId = ProductWaybills[i].WaybillId,
                            Count     = ProductWaybills[i].Count
                        });
                    }

                    /*if (id.HasValue)
                     * {
                     *  service.UpdElement(new CakeBindingModel
                     *  {
                     *      Id = id.Value,
                     *      CakeName = FCakeName.Text,
                     *      Price = Convert.ToInt32(FCakePrice.Text),
                     *      CakeIngredients = CakeIngredientBM
                     *  });
                     * }
                     * else
                     * {*/
                    if (ProductWaybillBM.Count == 0)
                    {
                        MessageBox.Show("Список продуктов пуст", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    int k = Convert.ToInt32(F_Stock.SelectedValue);
                    _serviceR.CreateReciept(new WaybillBM
                    {
                        ///////////////
                        Date            = F_Date.Value,
                        Summa           = Convert.ToDouble(F_Summa.Text.Replace(".", ",")),
                        StockId         = Convert.ToInt32(F_Stock.SelectedValue),
                        ProductWaybills = ProductWaybillBM
                    });
                    //  }
                    MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    DialogResult = DialogResult.OK;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }