Beispiel #1
0
        public ActionResult Edit(Level model)
        {
            try
            {
                // TODO: Add update logic here

                if (!(ModelState.IsValid))
                {
                    return View(model);
                }

                // TODO: Add insert logic here
               // List<Level> theLevel = work.LevelRepository.Get(a => a.LevelName.ToLower().Equals(model.LevelName.ToLower())).ToList();

                //int tracker = 0;
                //if (theLevel.Count > 0)
                //{
                //    foreach (Level l in theLevel)
                //    {
                //        if (!(string.IsNullOrEmpty(l.Type)))
                //        {
                //            if (!(string.IsNullOrEmpty(model.Type)))
                //            {

                //                if (l.Type.ToLower() == model.Type.ToLower())
                //                {
                //                    tracker = 1;
                //                    break;
                //                    // ModelState.AddModelError("", "Class has Already been Created");
                //                    // return View(model);
                //                }
                //            }

                //        }

                //        if ((string.IsNullOrEmpty(l.Type)))
                //        {
                //            if ((string.IsNullOrEmpty(model.Type)))
                //            {

                //                if (l.LevelName.ToLower() == model.LevelName.ToLower())
                //                {
                //                    tracker = 1;
                //                    break;
                //                    // ModelState.AddModelError("", "Class has Already been Created");
                //                    // return View(model);
                //                }
                //            }

                //        }
                //        //
                //        //  work.LevelRepository.Insert(model);
                //        //  work.Save();
                //        //  ModelState.AddModelError("", "Class has Already been Created");
                //        //  return View(model);
                //    }
                //}

                //if (tracker == 1)
                //{
                  //  ModelState.AddModelError("", "Class has Already been Created");
                  //  return View(model);
                //}
                //else
                //{
                //    work.LevelRepository.Update(model);
                //    work.Save();
                //}

                work.LevelRepository.Update(model);
               work.Save();
                //if (User.Identity.Name != "5000001")
                //{
                //    //AuditTrail audit = new AuditTrail { Date = DateTime.Now, Action = "Edited Class", UserID = User.Identity.Name };
                //    //work.AuditTrailRepository.Insert(audit);
                //    //work.Save();
                //}

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
Beispiel #2
0
        public ActionResult Create(Level model)
        {
            try
            {
                if (!(ModelState.IsValid))
                {
                    return View(model);
                }
                // TODO: Add insert logic here
                List<Level> theLevel = work.LevelRepository.Get(a => a.LevelName.ToLower().Equals(model.LevelName.ToLower())).ToList();

                int tracker = 0;
                if (theLevel.Count > 0)
                {
                    foreach (Level l in theLevel)
                    {
                        if (!(string.IsNullOrEmpty(l.Type)))
                        {
                            if (!(string.IsNullOrEmpty(model.Type)))
                            {

                                if (l.Type.ToLower() == model.Type.ToLower())
                                {
                                    tracker = 1;
                                    break;
                                    // ModelState.AddModelError("", "Class has Already been Created");
                                    // return View(model);
                                }
                            }

                        }

                        if ((string.IsNullOrEmpty(l.Type)))
                        {
                            if ((string.IsNullOrEmpty(model.Type)))
                            {

                                if (l.LevelName.ToLower() == model.LevelName.ToLower())
                                {
                                    tracker = 1;
                                    break;
                                    // ModelState.AddModelError("", "Class has Already been Created");
                                    // return View(model);
                                }
                            }

                        }
            //
                      //  work.LevelRepository.Insert(model);
                      //  work.Save();
                        //  ModelState.AddModelError("", "Class has Already been Created");
                        //  return View(model);
                    }
                }

                if (tracker == 1)
                {
                    ModelState.AddModelError("", "Class has Already been Created");
                    return View(model);
                }
                else
                {
                    work.LevelRepository.Insert(model);
                    work.Save();
                }
                //else
                //{

                //    work.LevelRepository.Insert(model);
                //    work.Save();
                //}

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
Beispiel #3
0
        public ActionResult Delete(Level model)
        {
            try
            {

                //   Int32 theId = Convert.ToInt32(SilverDaleSchools.Models.Encript.DecryptString(id, true));

                Level theLevel = work.LevelRepository.GetByID(model.LevelID);
                //string theL = model.LevelName;
                // TODO: Add delete logic here
                work.LevelRepository.Delete(theLevel);
                work.Save();
                if (User.Identity.Name != "5000001")
                {
                    //AuditTrail audit = new AuditTrail { Date = DateTime.Now, Action = "Deleted a Class Name:-"+ theL , UserID = User.Identity.Name };
                    //work.AuditTrailRepository.Insert(audit);
                    //work.Save();
                }
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }