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)); }
public static bool CheckReservation(Rezervimi rezervimi) { bool message = false; try { using (SqlConnection con = new SqlConnection(Connection.ConnectionString)) { SqlCommand cmd = new SqlCommand("ufn_KontrolloDatat", con); cmd.CommandType = System.Data.CommandType.Text; cmd.CommandText = "select dbo.[ufn_KontrolloDatat](@FillimiRezervimit,@MbarimiRezervimit,@FushaID)"; cmd.Parameters.AddWithValue("@FillimiRezervimit", rezervimi.FillimiRezervimit); cmd.Parameters.AddWithValue("@MbarimiRezervimit", rezervimi.MbarimiRezervimit); cmd.Parameters.AddWithValue("@FushaID", rezervimi.Fusha.FushaID); con.Open(); message = (bool)cmd.ExecuteScalar(); con.Close(); } return(message); } catch (Exception) { throw; } }
void Show() { try { rezervimi = BussinessRezervimi.GetAllRezervimetByID(rezervimiid); lblShowR.Text += rezervimi.RezervimiID.ToString(); dtMbarimiRezervimit.Text = rezervimi.MbarimiRezervimit.ToString(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btnShto_Click(object sender, EventArgs e) { try { Rezervimi newRezervim = new Rezervimi(); int fushaid = int.Parse(cmbFushat.SelectedValue.ToString()); int klientiid = int.Parse(cmbKlientat.SelectedValue.ToString()); DateTime dt = Convert.ToDateTime(dtDataeRezervimit.Value); DateTime dtF = Convert.ToDateTime(dtFillimiRezervimit.Value); DateTime dtM = Convert.ToDateTime(dtMbarimiRezervimit.Value); if (dtF.Date >= DateTime.Now && dtM.Date >= DateTime.Now) { if (dtM.Hour > dtF.Hour) { newRezervim.User = Form1.useri; Fusha fusha = new Fusha(); fusha.FushaID = fushaid; newRezervim.Fusha = fusha; newRezervim.Klienti = new Klienti(); newRezervim.Klienti.KlientiID = klientiid; newRezervim.DataERezervimit = DateTime.Now; newRezervim.FillimiRezervimit = dtF; newRezervim.MbarimiRezervimit = dtM; if (BussinessRezervimi.CheckReservation(newRezervim) == true) { MessageBox.Show("U shtua nje rezervim i ri"); BussinessRezervimi.InsertRezervim(newRezervim); this.Close(); } else { MessageBox.Show("Ekziston rezervim ne kete kohe"); } } else { MessageBox.Show("Data e mbarimit duhet të jete më e madhe se data e fillimit"); } } else { MessageBox.Show("Gabim në datë"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public static void Initialize(LibrarymsContext context) { context.Database.EnsureCreated(); //Look for any students. if (context.Libra.Any() || context.Klienti.Any() || context.Roles.Any()) { return; // DB has been seeded } var lirbat = new Libra[] { new Libra { Titulli = "When Harry Met Sally", Autori = "Filan Fisteku", E_Lire = true, } }; foreach (Libra s in lirbat) { context.Libra.Add(s); } context.SaveChanges(); var klientet = new Klienti[] { new Klienti { Emri = "Leutrim Ahmeti", Email = "*****@*****.**", Aktiv = true, NumriTel = "044444444" }, }; foreach (Klienti k in klientet) { context.Klienti.Add(k); } context.SaveChanges(); var rezervimi = new Rezervimi[] { new Rezervimi { Klienti_id = 1, Libra_id = 2, Aktiv = true } }; foreach (Rezervimi r in rezervimi) { context.Rezervimi.Add(r); } context.SaveChanges(); }
public ActionResult Rezervo(int?id) { if (Session["perdorues"] == null) { TempData["login"] = "******"; return(RedirectToAction("LogIn", "Perdorues")); } else { Rezervimi Rezervofilm = new Rezervimi(); Rezervofilm.filmi_salla = db.Filma_Salla.Where(x => x.Id_Filmi == id).ToList <Filma_Salla>(); Rezervofilm.film = db.Filmis.Where(x => x.Id_Filmi == id).FirstOrDefault(); return(View(Rezervofilm)); } }
public ActionResult Rezervo(Rezervimi rezervimi, int?id) { try { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } DateTime?orari = rezervimi.orari; var id_salla = db.Filma_Salla.Where(x => x.Id_Filmi == id && x.Orari == orari).Select(x => x.Id_Salla).FirstOrDefault(); var id_filma_salla = db.Filma_Salla.Where(x => x.Id_Filmi == id && x.Id_Salla == id_salla).Select(x => x.Id_filmi_salla).FirstOrDefault(); rezervimi.ID_Perdorues = Convert.ToInt32(Session["perdorues"]); rezervimi.Id_filmi_salla = id_filma_salla; if (nr_vende(id_filma_salla) == nr_rezervime(id_filma_salla)) { TempData["msg1"] = "<script>alert('Full, nuk ka me vende te lira');</script>"; db.Filma_Salla.Where(p => p.Id_filmi_salla == id_filma_salla).ToList().ForEach(x => x.Salla.Statusi = "Fully booked"); db.SaveChanges(); return(RedirectToAction("Rezervo", "Filmis", new { id = id })); } else { var v = db.Rezervimis.Where(x => x.Id_filmi_salla == id_filma_salla).Count(); rezervimi.vendi = v + 1; if (ModelState.IsValid) { db.Rezervimis.Add(rezervimi); db.SaveChanges(); TempData["rezsuccess"] = "<script>alert('U shtua me sukses!');</script>"; } return(RedirectToAction("Rezervimet", "Perdorues", new { id = Session["perdorues"] })); } } catch (Exception ex) { logger.ErrorException("Error u gjend ne Filmi Controller, rezervo Action", ex); return(RedirectToAction("Rezervimet", "Perdorues", new { id = Session["perdorues"] })); } }
public static void Edit(Rezervimi rezervim) { try { using (SqlConnection con = new SqlConnection(Connection.ConnectionString)) { SqlCommand cmd = new SqlCommand("sp_ShtyejRezervimin", con); cmd.CommandType = System.Data.CommandType.StoredProcedure; con.Open(); cmd.Parameters.AddWithValue("@RezervimiID", rezervim.RezervimiID); cmd.Parameters.AddWithValue("@MbarimiRezervimit", rezervim.MbarimiRezervimit); cmd.ExecuteNonQuery(); con.Close(); } } catch (Exception) { throw; } }
public static void Insert(Rezervimi rezervim) { try { using (SqlConnection con = new SqlConnection(Connection.ConnectionString)) { SqlCommand cmd = new SqlCommand("sp_ShtoRezervim", con); cmd.CommandType = System.Data.CommandType.StoredProcedure; con.Open(); cmd.Parameters.AddWithValue("@UserID", rezervim.User.UserID); cmd.Parameters.AddWithValue("@FushaID", rezervim.Fusha.FushaID); cmd.Parameters.AddWithValue("@KlientiID", rezervim.Klienti.KlientiID); cmd.Parameters.AddWithValue("@DataRezervimit", rezervim.DataERezervimit); cmd.Parameters.AddWithValue("@FillimiRezervimit", rezervim.FillimiRezervimit); cmd.Parameters.AddWithValue("@MbarimiRezervimit", rezervim.MbarimiRezervimit); cmd.ExecuteNonQuery(); con.Close(); } } catch (Exception) { throw; } }
public static bool CheckReservation(Rezervimi rezervimi) { return(AccessRezervimi.CheckReservation(rezervimi)); }
public static void EditRezervim(Rezervimi rezervim) { AccessRezervimi.Edit(rezervim); }
public static void InsertRezervim(Rezervimi rezervimi) { AccessRezervimi.Insert(rezervimi); }
public static Rezervimi GetByID(int rezervimiID) { Rezervimi rezervim = null; try { using (SqlConnection con = new SqlConnection(Connection.ConnectionString)) { SqlCommand cmd = new SqlCommand("sp_GetAllRezervimetByID", con); cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@RezervimiID", rezervimiID); con.Open(); using (SqlDataReader sqlr = cmd.ExecuteReader()) { if (sqlr.HasRows) { rezervim = new Rezervimi(); while (sqlr.Read()) { rezervim.RezervimiID = int.Parse(sqlr["RezervimiID"].ToString()); rezervim.User = new User(); rezervim.User.UserID = int.Parse(sqlr["UserID"].ToString()); rezervim.User.Emri = sqlr["User_Emri"].ToString(); rezervim.User.Mbiemri = sqlr["User_Mbiemri"].ToString(); rezervim.User.Email = sqlr["Email"].ToString(); rezervim.User.Password = sqlr["Password"].ToString(); rezervim.User.NrKontaktues = sqlr["User_NrKontaktues"].ToString(); rezervim.User.DataLindjes = Convert.ToDateTime(sqlr["DataELindjes"].ToString()); rezervim.User.Adresa = sqlr["Adresa"].ToString(); rezervim.User.TipiUser = new TipiUser(); rezervim.User.TipiUser.TipiID = int.Parse(sqlr["TipiID"].ToString()); rezervim.User.TipiUser.Pershkrimi = sqlr["Pershkrimi"].ToString(); rezervim.Fusha = new Fusha(); rezervim.Fusha.FushaID = int.Parse(sqlr["FushaID"].ToString()); rezervim.Fusha.FushaEMbuluar = (sqlr["FushaEMbuluar"].ToString() == "1" ? true : false); rezervim.Fusha.BariArtificial = (sqlr["BariArtificial"].ToString() == "1" ? true : false); rezervim.Fusha.Gjatesia = sqlr["Gjatesia"].ToString(); rezervim.Fusha.Gjeresia = sqlr["Gjeresia"].ToString(); rezervim.Fusha.CmimiFushes = double.Parse(sqlr["CmimiIFushes"].ToString()); rezervim.Klienti = new Klienti(); rezervim.Klienti.KlientiID = int.Parse(sqlr["KlientiID"].ToString()); rezervim.Klienti.Emri = sqlr["Klient_Emri"].ToString(); rezervim.Klienti.Mbiemri = sqlr["Klient_Mbiemri"].ToString(); rezervim.Klienti.NrKontaktues = sqlr["Klient_NrKontaktues"].ToString(); rezervim.DataERezervimit = Convert.ToDateTime(sqlr["DataERezervimit"].ToString()); rezervim.FillimiRezervimit = Convert.ToDateTime(sqlr["FillimiRezervimit"].ToString()); rezervim.MbarimiRezervimit = Convert.ToDateTime(sqlr["MbarimiRezervimit"].ToString()); rezervim.Pagesa = double.Parse(sqlr["Pagesa"].ToString()); rezervim.IsActive = bool.Parse(sqlr["IsActive"].ToString()); } } } con.Close(); } } catch (Exception) { throw; } return(rezervim); }