public async Task <IActionResult> Create([Bind("DataKthimit,Klienti_id,Libra_id,")] Huazimi huazimi)
        {
            try {
                if (ModelState.IsValid)
                {
                    huazimi.DataPritjes = DateTime.Now.AddMonths(1);
                    huazimi.Aktiv       = true;
                    _context.Huazimi.Add(huazimi);
                    Libra libri = _context.Libra.Where(t => t.id == huazimi.Libra_id).First();
                    libri.E_Lire = false;
                    libri.huazime++;
                    _context.Libra.Update(libri);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (DbUpdateException /* ex */)
            {
                //Log the error (uncomment ex variable name and write a log.
                ModelState.AddModelError("", "Unable to save changes. " +
                                         "Try again, and if the problem persists " +
                                         "see your system administrator.");
            }
            return(View(huazimi));
        }
Beispiel #2
0
        public async Task <IActionResult> Edit(int id, [Bind("id,Emri,Email,NumriTel,Aktiv,created_at,deleted_at")] Klienti k)
        {
            if (id != k.id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(k);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!KlientiExists(k.id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(k));
        }
        public async Task <IActionResult> Create(
            [Bind("id,Klienti_id,Libra_id,Aktiv")] Rezervimi r)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var huazimet = _context.Huazimi.Where(h => h.Klienti_id == r.Klienti_id && h.Aktiv == true).ToList();

                    foreach (Huazimi h in huazimet)
                    {
                        if (r.Libra_id == h.Libra_id)
                        {
                            return(RedirectToAction(nameof(Index)));
                        }
                    }

                    r.Aktiv      = true;
                    r.created_at = DateTime.Now;
                    _context.Rezervimi.Add(r);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (DbUpdateException /* ex */)
            {
                //Log the error (uncomment ex variable name and write a log.
                ModelState.AddModelError("", "Unable to save changes. " +
                                         "Try again, and if the problem persists " +
                                         "see your system administrator.");
            }
            return(View(r));
        }
Beispiel #4
0
        public async Task <IActionResult> Create(Pagesa pagesa)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    pagesa.Active       = true;
                    pagesa.DataEPageses = DateTime.Now;
                    switch (pagesa.Shuma)
                    {
                    case 5:
                        pagesa.DataESkadimit = DateTime.Now.AddMonths(1);
                        break;

                    case 10:
                        pagesa.DataESkadimit = DateTime.Now.AddMonths(3);
                        break;

                    case 15:
                        pagesa.DataESkadimit = DateTime.Now.AddMonths(6);
                        break;
                    }
                    _context.Add(pagesa);
                    Klienti klienti = _context.Klienti.Where(k => k.id == pagesa.Klienti_id).First();
                    klienti.Aktiv = true;
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }catch (DbUpdateException ex)
            {
                //Log the error (uncomment ex variable name and write a log.
                ModelState.AddModelError("", "Unable to save changes. " +
                                         "Try again, and if the problem persists " +
                                         "see your system administrator.");
            }
            return(View(pagesa));
        }
        public async Task <IActionResult> Create(
            [Bind("Titulli,Autori")] Libra libra)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    libra.E_Lire = true;
                    _context.Add(libra);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (DbUpdateException /* ex */)
            {
                //Log the error (uncomment ex variable name and write a log.
                ModelState.AddModelError("", "Unable to save changes. " +
                                         "Try again, and if the problem persists " +
                                         "see your system administrator.");
            }
            return(View(libra));
        }