Exemplo n.º 1
0
        public ActionResult ModifikoLendenGet(int LendaID, int ProfesoriID, int ProfesoriLendaID)
        {
            Session["L"] = LendaID;
            var lenda      = db.tblLenda.Find(LendaID);
            var profesoret = (from p in db.tblPerdoruesi.Where(p => p.RoliID == 3)
                              select new
            {
                ProfesoriID = p.PerdoruesiID,
                EmriMbiemri = p.Emri + " " + p.Mbiemri
            }).ToList();

            ViewBag.Profesoret = new SelectList(profesoret, "ProfesoriID", "EmriMbiemri");

            if (lenda == null)
            {
                Session["mesazhi"] = "Lenda me kete numer nuk eshte gjetur.";
                return(RedirectToAction("index"));
            }
            else
            {
                var mbushModelin = new LendaList();
                mbushModelin.LendaID          = lenda.LendaID;
                mbushModelin.Emri             = lenda.Emri;
                mbushModelin.Pershkrimi       = lenda.Pershkrimi;
                mbushModelin.ProfesoriID      = ProfesoriID;
                mbushModelin.ProfesoriLendaID = ProfesoriLendaID;

                return(PartialView("_ModifikoLendenGet", mbushModelin));
            }
        }
Exemplo n.º 2
0
        public ActionResult ModifikoLendenPost(LendaList modeli)
        {
            try
            {
                //var LendaID=int.Parse(Session[])
                var t = db.tblLenda.FirstOrDefault(x => x.Emri == modeli.Emri);
                if (t == null)
                {
                    var lendaDB = db.tblLenda.Find(modeli.LendaID);
                    if (lendaDB == null)
                    {
                        Session["mesazhi"] = "Lenda nuk ekziston";
                        return(RedirectToAction("Index"));
                    }
                    lendaDB.Emri            = modeli.Emri;
                    lendaDB.Pershkrimi      = modeli.Pershkrimi;
                    db.Entry(lendaDB).State = EntityState.Modified;
                    db.SaveChanges();

                    var lendaProfesoriDB = db.tblProfesoriLenda.Find(modeli.ProfesoriLendaID);
                    lendaProfesoriDB.ProfesoriID     = modeli.ProfesoriID;
                    db.Entry(lendaProfesoriDB).State = EntityState.Modified;
                    db.SaveChanges();
                    Session["mesazhi"] = "Lenda u modifikua me sukses.";

                    return(RedirectToAction("Index"));
                }
                else
                {
                    var check2 = db.tblProfesoriLenda.Any(x => x.ProfesoriID == modeli.ProfesoriID && x.LendaID == t.LendaID);
                    if (check2)
                    {
                        Session["Mesazhi"] = "Lenda me kete profesor, ekziston ne sistem!";
                        return(RedirectToAction("Index"));
                    }
                    var lendaDB = db.tblLenda.Find(modeli.LendaID);
                    if (lendaDB == null)
                    {
                        Session["mesazhi"] = "Lenda nuk ekziston";
                        return(RedirectToAction("Index"));
                    }
                    lendaDB.Emri            = modeli.Emri;
                    lendaDB.Pershkrimi      = modeli.Pershkrimi;
                    db.Entry(lendaDB).State = EntityState.Modified;
                    db.SaveChanges();

                    var lendaProfesoriDB = db.tblProfesoriLenda.Find(modeli.ProfesoriLendaID);
                    lendaProfesoriDB.ProfesoriID     = modeli.ProfesoriID;
                    db.Entry(lendaProfesoriDB).State = EntityState.Modified;
                    db.SaveChanges();
                    Session["mesazhi"] = "Lenda u modifikua me sukses.";

                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception e)
            {
                Session["Mesazhi"] = "Ka ndodhur nje gabim. " + e.Message;

                return(RedirectToAction("Index"));
            }
        }