public ActionResult Delete(int?id, nilAkhir per)
 {
     try
     {
         // TODO: Add delete logic here
         nilAkhir nilAkhirDb = new nilAkhir();
         if (ModelState.IsValid)
         {
             if (id == null)
             {
                 return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
             }
             nilAkhirDb = db.nilAkhirCt.Find(id);
             if (nilAkhirDb == null)
             {
                 return(HttpNotFound());
             }
             db.nilAkhirCt.Remove(nilAkhirDb);
             db.SaveChanges();
             return(RedirectToAction("Index"));
         }
         return(View(nilAkhirDb));
     }
     catch
     {
         return(View());
     }
 }
        //
        // GET: /nilAkhir/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            nilAkhir nilAkhirDb = db.nilAkhirCt.Find(id);

            if (nilAkhirDb == null)
            {
                return(HttpNotFound());
            }
            return(View(nilAkhirDb));
        }
 public ActionResult Create(nilAkhir nilAkhirDb)
 {
     try
     {
         // TODO: Add insert logic here
         if (ModelState.IsValid)
         {
             db.nilAkhirCt.Add(nilAkhirDb);
             db.SaveChanges();
             return(RedirectToAction("Index"));
         }
         return(View(nilAkhirDb));
     }
     catch
     {
         return(View());
     }
 }
 public ActionResult Edit(nilAkhir nilAkhirDb)
 {
     try
     {
         // TODO: Add update logic here
         if (ModelState.IsValid)
         {
             db.Entry(nilAkhirDb).State = System.Data.Entity.EntityState.Modified;
             db.SaveChanges();
             return(RedirectToAction("Index"));
         }
         return(View(nilAkhirDb));
     }
     catch
     {
         return(View());
     }
 }
        //
        // GET: /nilAkhir/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            nilAkhir nilAkhirDb = db.nilAkhirCt.Find(id);

            if (nilAkhirDb == null)
            {
                return(HttpNotFound());
            }
            dropDownSekolah(nilAkhirDb.sekolahCode);
            dropDownKelas(nilAkhirDb.kelasCode);
            dropDownSiswa(nilAkhirDb.nis);
            dropDownMapel(nilAkhirDb.mapelCode);
            dropDownGuru(nilAkhirDb.nik);
            return(View(nilAkhirDb));
        }
        public ActionResult Create(nilUtsUas nilUtsUasDb)
        {
            try
            {
                // TODO: Add insert logic here
                if (ModelState.IsValid)
                {
                    db.nilUtsUasCt.Add(nilUtsUasDb);
                    db.SaveChanges();

                    try
                    {
                        var dataUpdate = (from NilAkhir in db.nilAkhirCt
                                          where
                                          NilAkhir.sekolahCode == nilUtsUasDb.sekolahCode &&
                                          NilAkhir.kelasCode == nilUtsUasDb.kelasCode &&
                                          NilAkhir.nis == nilUtsUasDb.nis &&
                                          NilAkhir.mapelCode == nilUtsUasDb.mapelCode &&
                                          NilAkhir.nik == nilUtsUasDb.nik
                                          select NilAkhir).ToList();


                        double dataNilKi3 = (from NilAkhir in db.nilPengetahuanKognitifKI3Ct
                                             where
                                             NilAkhir.sekolahCode == nilUtsUasDb.sekolahCode &&
                                             NilAkhir.kelasCode == nilUtsUasDb.kelasCode &&
                                             NilAkhir.nis == nilUtsUasDb.nis &&
                                             NilAkhir.mapelCode == nilUtsUasDb.mapelCode &&
                                             NilAkhir.nik == nilUtsUasDb.nik
                                             select NilAkhir.KI3nilaiTotal).Average();

                        double dataNilKi4 = (from NilAkhir in db.nilKetrampilanPsikomotorikKI4Ct
                                             where
                                             NilAkhir.sekolahCode == nilUtsUasDb.sekolahCode &&
                                             NilAkhir.kelasCode == nilUtsUasDb.kelasCode &&
                                             NilAkhir.nis == nilUtsUasDb.nis &&
                                             NilAkhir.mapelCode == nilUtsUasDb.mapelCode &&
                                             NilAkhir.nik == nilUtsUasDb.nik
                                             select NilAkhir.KI4nilaiTotal).Average();

                        double dataNilSikap = (from NilAkhir in db.nilSikapKI1KI2Ct
                                               where
                                               NilAkhir.sekolahCode == nilUtsUasDb.sekolahCode &&
                                               NilAkhir.kelasCode == nilUtsUasDb.kelasCode &&
                                               NilAkhir.nis == nilUtsUasDb.nis &&
                                               NilAkhir.mapelCode == nilUtsUasDb.mapelCode &&
                                               NilAkhir.nik == nilUtsUasDb.nik
                                               select NilAkhir.KI1KI2nilaiTotal).Average();

                        double dataNilUts = (from NilAkhir in db.nilUtsUasCt
                                             where
                                             NilAkhir.sekolahCode == nilUtsUasDb.sekolahCode &&
                                             NilAkhir.kelasCode == nilUtsUasDb.kelasCode &&
                                             NilAkhir.nis == nilUtsUasDb.nis &&
                                             NilAkhir.mapelCode == nilUtsUasDb.mapelCode &&
                                             NilAkhir.nik == nilUtsUasDb.nik
                                             select NilAkhir.nilaiUts).Average();

                        double dataNilUas = (from NilAkhir in db.nilUtsUasCt
                                             where
                                             NilAkhir.sekolahCode == nilUtsUasDb.sekolahCode &&
                                             NilAkhir.kelasCode == nilUtsUasDb.kelasCode &&
                                             NilAkhir.nis == nilUtsUasDb.nis &&
                                             NilAkhir.mapelCode == nilUtsUasDb.mapelCode &&
                                             NilAkhir.nik == nilUtsUasDb.nik
                                             select NilAkhir.nilaiUas).Average();


                        if (dataUpdate.Count > 0)
                        {
                            //update here

                            foreach (nilAkhir nilAkhirUpdate in dataUpdate)
                            {
                                //Field which will be update
                                nilAkhirUpdate.nilKI3   = dataNilKi3;
                                nilAkhirUpdate.nilKI4   = dataNilKi4;
                                nilAkhirUpdate.nilSikap = dataNilSikap;
                                nilAkhirUpdate.nilUts   = dataNilUts;
                                nilAkhirUpdate.nilUas   = dataNilUas;
                                nilAkhirUpdate.nilNaKI3 = (((dataNilKi3 * 3) + (dataNilUts * 1) + (dataNilUas * 2)) / 6);
                            }
                        }
                        else
                        {
                            //insert here
                            nilAkhir nilAkhirInsert = new nilAkhir();
                            nilAkhirInsert.sekolahCode = nilUtsUasDb.sekolahCode;
                            nilAkhirInsert.kelasCode   = nilUtsUasDb.kelasCode;
                            nilAkhirInsert.nis         = nilUtsUasDb.nis;
                            nilAkhirInsert.mapelCode   = nilUtsUasDb.mapelCode;
                            nilAkhirInsert.nik         = nilUtsUasDb.nik;
                            nilAkhirInsert.nilKI3      = dataNilKi3;
                            nilAkhirInsert.nilKI4      = dataNilKi4;
                            nilAkhirInsert.nilSikap    = dataNilSikap;
                            nilAkhirInsert.nilUts      = dataNilUts;
                            nilAkhirInsert.nilUas      = dataNilUas;
                            nilAkhirInsert.nilNaKI3    = (((dataNilKi3 * 3) + (dataNilUts * 1) + (dataNilUas * 2)) / 6);
                            db.nilAkhirCt.Add(nilAkhirInsert);
                        }
                    }
                    catch
                    {
                        //log the error
                        return(RedirectToAction("Index"));
                    }

                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                return(View(nilUtsUasDb));
            }
            catch
            {
                return(View());
            }
        }