Пример #1
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"));
        }
Пример #2
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));
        }
Пример #3
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"));
        }