Example #1
0
 public ActionResult Edit(int id = 0)
 {
     if (id != 0)
     {
         try
         {
             SchoolBookDBEntities db = new SchoolBookDBEntities();
             School          obj     = db.Schools.Find(id);
             SchoolViewModel school  = new SchoolViewModel();
             school.SchoolName        = obj.Name;
             school.City              = obj.City;
             school.Address           = obj.Address;
             school.PhoneNo           = obj.PhoneNo;
             school.AdmissionFee      = obj.Adm_Fee;
             school.FeePG_Middle      = obj.Fee_PG_Middle;
             school.FeeMatric_Olevels = obj.Fee_Matric_OLevel;
             school.file              = obj.ImageUrl;
             school.id = obj.SchoolD;
             return(View(school));
         }
         catch
         {
             return(RedirectToAction("Dashboard"));
         }
     }
     else
     {
         return(RedirectToAction("Dashboard"));
     }
 }
Example #2
0
        public ActionResult Dashboard()
        {
            SchoolBookDBEntities   db          = new SchoolBookDBEntities();
            List <School>          Schools     = db.Schools.ToList();
            List <SchoolViewModel> SchoolsView = new List <SchoolViewModel>();

            foreach (School obj in Schools)
            {
                if (obj.AddedBy == User.Identity.GetUserId())
                {
                    SchoolViewModel school = new SchoolViewModel();
                    school.SchoolName        = obj.Name;
                    school.City              = obj.City;
                    school.Address           = obj.Address;
                    school.PhoneNo           = obj.PhoneNo;
                    school.AdmissionFee      = obj.Adm_Fee;
                    school.FeePG_Middle      = obj.Fee_PG_Middle;
                    school.FeeMatric_Olevels = obj.Fee_Matric_OLevel;
                    school.file              = obj.ImageUrl;
                    school.id = obj.SchoolD;
                    SchoolsView.Add(school);
                }
            }

            return(View(SchoolsView));
        }
Example #3
0
        public ActionResult Edit(SchoolViewModel model, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    if (file != null)
                    {
                        SchoolBookDBEntities db = new SchoolBookDBEntities();
                        School obj = db.Schools.Find(model.id);
                        string previous_image_path = obj.ImageUrl;
                        if (System.IO.File.Exists(previous_image_path))
                        {
                            System.IO.File.Delete(previous_image_path);
                        }
                        string fileName = Path.GetFileName(file.FileName);
                        string path     = "~/Content/Images/" + fileName;
                        file.SaveAs(Server.MapPath(path));
                        model.file = path;

                        School school = db.Schools.Single(s => s.SchoolD == model.id);
                        school.Name              = model.SchoolName;
                        school.Address           = model.Address;
                        school.City              = model.City;
                        school.Adm_Fee           = model.AdmissionFee;
                        school.Fee_PG_Middle     = model.FeePG_Middle;
                        school.Fee_Matric_OLevel = model.FeeMatric_Olevels;
                        school.ImageUrl          = model.file;
                        school.PhoneNo           = model.PhoneNo;
                        db.SaveChanges();

                        ViewBag.FileStatus = "Succesfully Edited";
                    }
                    else
                    {
                        SchoolBookDBEntities db = new SchoolBookDBEntities();
                        School obj    = db.Schools.Find(model.id);
                        School school = db.Schools.Single(s => s.SchoolD == model.id);
                        school.Name              = model.SchoolName;
                        school.Address           = model.Address;
                        school.City              = model.City;
                        school.Adm_Fee           = model.AdmissionFee;
                        school.Fee_PG_Middle     = model.FeePG_Middle;
                        school.Fee_Matric_OLevel = model.FeeMatric_Olevels;
                        school.PhoneNo           = model.PhoneNo;
                        db.SaveChanges();

                        ViewBag.FileStatus = "Succesfully Edited";
                    }
                }
                catch
                {
                    ViewBag.FileStatus = "Some error in Updating";
                }
            }
            return(View("Edit"));
        }
Example #4
0
        public ActionResult Index()
        {
            SchoolBookDBEntities   db      = new SchoolBookDBEntities();
            List <School>          Schools = db.Schools.ToList();
            List <SchoolViewModel> schools = new List <SchoolViewModel>();
            List <Rating_Reviews>  ratings = db.Rating_Reviews.ToList();
            List <SchoolViewModel> Output  = new List <SchoolViewModel>();

            foreach (School obj in Schools)
            {
                SchoolViewModel s = new SchoolViewModel();
                s.SchoolName = obj.Name;
                s.City       = obj.City;
                s.PhoneNo    = obj.PhoneNo;
                s.file       = obj.ImageUrl;
                s.id         = obj.SchoolD;
                int Ratings       = 0;
                int Ratings_Count = 0;
                foreach (Rating_Reviews r in ratings)
                {
                    if (r.SchoolID == obj.SchoolD)
                    {
                        Ratings       += r.Rating;
                        Ratings_Count += 1;
                    }
                }
                if (Ratings_Count == 0)
                {
                    s.Rating = Ratings;
                }
                else
                {
                    s.Rating = Ratings / Ratings_Count;
                }
                schools.Add(s);
            }
            schools.OrderBy(x => x.Rating);
            schools.Reverse();
            int index = 0;

            if (schools.Count() > 6)
            {
                index = 6;
            }
            else
            {
                index = schools.Count();
            }
            for (int i = 0; i < index; i++)
            {
                Output.Add(schools[i]);
            }
            return(View(Output));
        }
Example #5
0
 public ActionResult Details(int id = 0)
 {
     if (id != 0)
     {
         try
         {
             SchoolBookDBEntities db       = new SchoolBookDBEntities();
             School                school  = db.Schools.Find(id);
             SchoolViewModel       obj     = new SchoolViewModel();
             List <Rating_Reviews> ratings = db.Rating_Reviews.ToList();
             obj.SchoolName        = school.Name;
             obj.City              = school.City;
             obj.Address           = school.Address;
             obj.AdmissionFee      = school.Adm_Fee;
             obj.FeePG_Middle      = school.Fee_PG_Middle;
             obj.FeeMatric_Olevels = school.Fee_Matric_OLevel;
             obj.PhoneNo           = school.PhoneNo;
             obj.file              = school.ImageUrl;
             obj.id = school.SchoolD;
             int Ratings       = 0;
             int Ratings_Count = 0;
             obj.Ratings_List = new List <Rating_Reviews>();
             foreach (Rating_Reviews r in ratings)
             {
                 if (r.SchoolID == obj.id)
                 {
                     Ratings       += r.Rating;
                     Ratings_Count += 1;
                     obj.Ratings_List.Add(r);
                 }
             }
             if (Ratings_Count == 0)
             {
                 obj.Rating = Ratings;
             }
             else
             {
                 obj.Rating = Ratings / Ratings_Count;
             }
             return(View("Details", obj));
         }
         catch
         {
             return(RedirectToAction("Schools"));
         }
     }
     else
     {
         return(RedirectToAction("Schools"));
     }
 }
Example #6
0
        public ActionResult Rate(int id, Rating_Review model, string url)
        {
            SchoolBookDBEntities db = new SchoolBookDBEntities();
            Rating_Reviews       r  = new Rating_Reviews();
            var    user             = db.AspNetUsers.Single(u => u.UserName == User.Identity.Name);
            string name             = user.FullName;

            r.AddedBy  = name;
            r.SchoolID = id;
            r.Rating   = model.Rating;
            if (model.Review != null)
            {
                r.Review = model.Review;
            }
            db.Rating_Reviews.Add(r);
            db.SaveChanges();
            return(Redirect(url));
        }
Example #7
0
        public ActionResult Add(SchoolViewModel obj, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    if (file != null)
                    {
                        //var allowedExtensions = new[] {".Jpg", ".png", ".jpg", "jpeg" };
                        SchoolBookDBEntities db = new SchoolBookDBEntities();
                        School school           = new School();
                        school.Name              = obj.SchoolName;
                        school.City              = obj.City;
                        school.Address           = obj.Address;
                        school.PhoneNo           = obj.PhoneNo;
                        school.Adm_Fee           = obj.AdmissionFee;
                        school.Fee_PG_Middle     = obj.FeePG_Middle;
                        school.Fee_Matric_OLevel = obj.FeeMatric_Olevels;
                        school.AddedBy           = User.Identity.GetUserId();

                        //var ext = Path.GetExtension(file.FileName);

                        string fileName = Path.GetFileName(file.FileName);
                        string path     = "~/Content/Images/" + fileName;
                        file.SaveAs(Server.MapPath(path));

                        school.ImageUrl = path;
                        db.Schools.Add(school);
                        db.SaveChanges();
                        SchoolViewModel vm = new SchoolViewModel();
                        return(RedirectToAction("Add"));
                    }

                    ViewBag.FileStatus = "School Successfully Added";
                }
                catch
                {
                    ViewBag.FileStatus = "Some Error Occurred";
                }
            }
            return(View("Add"));
        }
Example #8
0
        public ActionResult Schools()
        {
            SchoolBookDBEntities   db      = new SchoolBookDBEntities();
            List <School>          Schools = db.Schools.ToList();
            List <SchoolViewModel> schools = new List <SchoolViewModel>();
            List <Rating_Reviews>  ratings = db.Rating_Reviews.ToList();

            foreach (School obj in Schools)
            {
                SchoolViewModel s = new SchoolViewModel();
                s.SchoolName = obj.Name;
                s.City       = obj.City;
                s.PhoneNo    = obj.PhoneNo;
                s.file       = obj.ImageUrl;
                s.id         = obj.SchoolD;
                int Ratings       = 0;
                int Ratings_Count = 0;
                foreach (Rating_Reviews r in ratings)
                {
                    if (r.SchoolID == obj.SchoolD)
                    {
                        Ratings       += r.Rating;
                        Ratings_Count += 1;
                    }
                }
                if (Ratings_Count == 0)
                {
                    s.Rating = Ratings;
                }
                else
                {
                    s.Rating = Ratings / Ratings_Count;
                }
                schools.Add(s);
            }
            return(View(schools));
        }