Exemple #1
0
 private void btnGrant_Click(object sender, EventArgs e)
 {
     try
     {
         if (txtCount.CheckNull())
         {
             return;
         }
         if (!txtCount.CheckInt())
         {
             return;
         }
         if (comboNoteBook.SelectedItem == null)
         {
             CheckData.ErrorMessage("Error , Plase Select notebook from the combo box");
             return;
         }
         if (reseller == null)
         {
             CheckData.ErrorMessage("Error , Plase Select reseller ");
             return;
         }
         // Todo Check Limit of NoteBookSerials Count
         var  noteBook                 = noteBooks.First(x => x.Id == (int)comboNoteBook.SelectedValue);
         int  NoteBookSerialsCount     = noteBook.NoteBookSerials.Count();
         var  resellerAndNoteBookCount = resellerAndNoteBooks.FirstOrDefault(x => x.NoteBookId == (int)comboNoteBook.SelectedValue);
         int  requiredCount            = Convert.ToInt32(txtCount.Text);
         bool check;
         if (resellerAndNoteBookCount == null)
         {
             check = NoteBookSerialsCount < requiredCount;
         }
         else
         {
             int AllowedNumber = NoteBookSerialsCount - resellerAndNoteBookCount.Count;
             check = AllowedNumber < requiredCount;
         }
         if (check)
         {
             CheckData.ErrorMessage("Error , You have exceeded your notebook count limit ");
             return;
         }
         //----------------------------------------------------------------------
         ResellerAndNoteBook resellerAndNoteBook = CallAPI.PostObjectAndGetObject <ResellerAndNoteBook, ResellerAndNoteBook>(null, "GrantNoteBooksToReseller",
                                                                                                                             reseller.Id.ToString(), comboNoteBook.SelectedValue.ToString(), txtCount.Text);
         MessageBox.Show("Added Done", "Done", MessageBoxButtons.OK, MessageBoxIcon.Information);
         FillGrid();
     }
     catch (Exception ex)
     {
         CheckData.ErrorMessage();
     }
 }
Exemple #2
0
        public async Task <ActionResult <ResellerAndNoteBook> > GrantNoteBooksToReseller(int resellerId, int noteBookId, int count)
        {
            ResellerAndNoteBook resellerAndNoteBook = _context.ResellerAndNoteBooks.FirstOrDefault(x => x.NoteBookId == noteBookId && x.ResellerId == resellerId);

            if (resellerAndNoteBook == null)
            {
                resellerAndNoteBook = new ResellerAndNoteBook
                {
                    ResellerId    = resellerId,
                    Count         = count,
                    NoteBookId    = noteBookId,
                    LastGrantDate = DateTime.Now
                };
                _context.ResellerAndNoteBooks.Add(resellerAndNoteBook);
            }
            else
            {
                resellerAndNoteBook.Count        += count;
                resellerAndNoteBook.LastGrantDate = DateTime.Now;
            }
            await _context.SaveChangesAsync();

            return(resellerAndNoteBook);
        }