private async void dgvD_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (dgvD.Columns[e.ColumnIndex].Name == "DeactivateDiscount") { var idobj = dgvD.Rows[e.RowIndex].Cells[0].Value; var id = int.Parse(idobj.ToString()); var discount = await _apiServiceD.GetById <Model.Discount>(id); if (discount.Active == true) { DiscountUpsertRequest req = new DiscountUpsertRequest { UserId = discount.UserId, Active = false, DiscountTypeId = discount.DiscountTypeId, RestaurantMenuItemId = discount.RestaurantMenuItemId, ItemCategoryId = discount.ItemCategoryId, ItemTypeId = discount.ItemTypeId, DiscountDate = discount.DiscountDate, DiscountValue = discount.DiscountValue }; await _apiServiceD.Update <Model.Discount>(id, req); MessageBox.Show("Popust uspješno deaktiviran", "Deaktivacija popusta", MessageBoxButtons.OK, MessageBoxIcon.Information); frmDiscountManagment_Load(this, null); } else { MessageBox.Show("Popust nije aktivan", "Deaktivacija popusta", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } }
private async void dgvItems_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (dgvItems.Columns[e.ColumnIndex].Name == "AddDiscount") { var idobj = cmbDT.SelectedValue; if (int.TryParse(idobj.ToString(), out int id)) { if (id == 14) { var objRMI = dgvItems.Rows[e.RowIndex].Cells[0].Value.ToString(); int rmiId = int.Parse(objRMI); var req = new DiscountUpsertRequest { UserId = _id.Value, Active = true, DiscountDate = DateTime.Now, DiscountValue = nudDV.Value, DiscountTypeId = id, RestaurantMenuItemId = rmiId }; Model.Discount r = null; r = await _apiServiceD.Insert <Model.Discount>(req); if (r != null) { MessageBox.Show("Popust uspješno dodan!", "Obavijest", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } } }
private async void button1_Click(object sender, EventArgs e) { var idobj = cmbDT.SelectedValue; if (int.TryParse(idobj.ToString(), out int id)) { if (id != 14) { DiscountUpsertRequest req = CreateRequest(id); Model.Discount r = null; r = await _apiServiceD.Insert <Model.Discount>(req); if (r != null) { MessageBox.Show("Popust uspješno dodan!", "Obavijest", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { MessageBox.Show("Izabrali ste popust na pojedinačnu stavku." + "Molimo vas da pritisnete dugme za dodavanje popusta pored stavke za koju" + " želite dodijeliti popust!", "Greška", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } }
private DiscountUpsertRequest CreateRequest(int id) { var req = new DiscountUpsertRequest { UserId = _id.Value, Active = true, DiscountDate = DateTime.Now, DiscountValue = nudDV.Value, DiscountTypeId = id, }; if (id == 1) { req.ItemTypeId = 1; } else if (id == 2) { req.ItemTypeId = 2; } else if (id == 3) { req.ItemCategoryId = 1; } else if (id == 4) { req.ItemCategoryId = 2; } else if (id == 5) { req.ItemCategoryId = 3; } else if (id == 6) { req.ItemCategoryId = 5; } else if (id == 7) { req.ItemCategoryId = 6; } else if (id == 8) { req.ItemCategoryId = 7; } else if (id == 9) { req.ItemCategoryId = 8; } else if (id == 10) { req.ItemCategoryId = 10; } else if (id == 11) { req.ItemCategoryId = 11; } return(req); }