示例#1
0
        public ActionResult createSchool(string name, int type, string url, string callback)
        {
            ajaxReturnData data = new ajaxReturnData();

            try {

                using (ApplicationDbContext DB = new ApplicationDbContext())
                {

                    if (DB.Schools.Where(s => s.url == url).Any())
                    {
                        data.message = "School already be existing; No need to re-exist it";
                        data.statusCode = (int)statusCodes.fail;
                    }
                    else
                    {
                        School school = new School();
                        school.features = new SchoolFeatures();
                        school.content = new List<Content>();
                        school.type = type;
                        school.url = url;
                        
                        DB.Schools.Add(school);
                        DB.SaveChanges();

                        school.addContent(DB, "name", name);

                        data.message = "School "+name+" added.";

                        if (string.IsNullOrEmpty(callback))
                        {
                            data.statusCode = (int)statusCodes.success;
                        }
                        else
                        {
                            data.statusCode = (int)statusCodes.successRun;
                            data.callback = callback;
                        }

                    }
                }
                

            }
            catch(Exception ex)
            {
                data.message = "Failed to create school; " + ex.Message;
                data.statusCode = (int)statusCodes.fail;
            }

            
            return Json(data);
        }
示例#2
0
        public ActionResult deleteSchool(int schoolID, string callback)
        {
            ajaxReturnData data = new ajaxReturnData();

            using (ApplicationDbContext DB = new ApplicationDbContext())
            {
                try
                {
                    School doomedSchool = new School();
                    doomedSchool.id = schoolID;
                    doomedSchool.features = new SchoolFeatures();
                    DB.Schools.Attach(doomedSchool);
                    DB.Schools.Remove(doomedSchool);

                    DB.SaveChanges();



                    if (string.IsNullOrEmpty(callback))
                    {
                        data.statusCode = (int)statusCodes.success;
                    }
                    else
                    {
                        data.statusCode = (int)statusCodes.successRun;
                        data.callback = callback;
                    }

                    data.message = "school removed";
                    return Json(data);
                }
                catch (Exception ex)
                {
                    data.statusCode = (int)statusCodes.fail;
                    data.message = "Error: " + ex.Message;
                    return Json(data);
                }

            }
        }
示例#3
0
        public ActionResult editLocation(int locationID, int schoolID, string description, Location location, string callback, HttpPostedFileWrapper image)
        {
            ajaxReturnData data = new ajaxReturnData();

            try
            {
                using (ApplicationDbContext DB = new ApplicationDbContext())
                {
                    location.id = locationID;

                    DB.Locations.Attach(location);
                    DB.Entry(location).State = EntityState.Unchanged;
                    DB.Entry(location).Property(l => l.name).IsModified = true;
                    //DB.Entry(location).Property(l => l.city).IsModified = true;
                    location.addContent(DB, "description", description);


                    if (image != null && image.ContentLength > 0)
                    {

                        string path = "/content/images/uploads/locations/" + locationID;
                        //bool existsfirst = System.IO.Directory.Exists(Server.MapPath(path));
                        bool exists = System.IO.Directory.Exists(Server.MapPath(path));
                        if (!exists)
                        {
                            Directory.CreateDirectory(Server.MapPath(path));
                        }

                        path = path + "/locationImage" + Path.GetExtension(image.FileName);
                        image.SaveAs(Server.MapPath(path));
                        location.image = path;
                        DB.Entry(location).Property(l => l.image).IsModified = true;
                    }
                    DB.SaveChanges();

                    School school = new School();
                    school.id = schoolID;
                    //school.schoolLocation = location;
                    school.locationID = location.id;
                    school.features = new SchoolFeatures();
                    DB.Schools.Attach(school);
                    DB.Entry(school).State = EntityState.Unchanged;
                    DB.Entry(school).Property(s => s.locationID).IsModified = true;

                    DB.SaveChanges();

                    


                }


                if (string.IsNullOrEmpty(callback))
                {
                    data.statusCode = (int)statusCodes.success;
                }
                else
                {
                    data.statusCode = (int)statusCodes.successRun;
                    data.callback = callback;
                }

                data.message = "location updated";
                return Json(data);
            }
            catch (Exception ex)
            {
                data.statusCode = (int)statusCodes.fail;
                data.message = "Failed to update location; " + ex.Message;
                return Json(data);
            }
        }
示例#4
0
        public ActionResult editSchoolFeatures(int schoolID, School school, string callback, string uniqueFeatureText, HttpPostedFileWrapper featuresImage, string uniqueFeature = "")
        {
            ajaxReturnData data = new ajaxReturnData();

            try
            {
                using (ApplicationDbContext DB = new ApplicationDbContext())
                {
                    school.id = schoolID;

                    if (!String.IsNullOrWhiteSpace(uniqueFeature))
                    {
                        school.addContent(DB, "USP", uniqueFeature);
                        school.addContent(DB, "uniqueFeatureText", uniqueFeatureText);
                        DB.SaveChanges();
                    }

                    

                    //features is a complex type, meaning its adding as table columns to schools and can not be null on an update
                    if (school.features == null)
                    {
                        school.features = new SchoolFeatures();
                    }


                    DB.Schools.Attach(school);
                    DB.Entry(school).State = EntityState.Unchanged;

                    if(school.features != null)
                    {
                        DB.Entry(school).Property(s => s.features.studentCafe).IsModified = true;
                        DB.Entry(school).Property(s => s.features.acceptsBeginners).IsModified = true;
                        DB.Entry(school).Property(s => s.features.wifiInCommonAreas).IsModified = true;
                        DB.Entry(school).Property(s => s.features.studentLounge).IsModified = true;
                        DB.Entry(school).Property(s => s.features.studentLounge24hour).IsModified = true;
                        DB.Entry(school).Property(s => s.features.englishStaff).IsModified = true;
                        DB.Entry(school).Property(s => s.features.fullTimeJobSupport).IsModified = true;
                        DB.Entry(school).Property(s => s.features.partTimeJobSupport).IsModified = true;
                        DB.Entry(school).Property(s => s.features.interactWithJapanese).IsModified = true;
                        DB.Entry(school).Property(s => s.features.smallClassSizes).IsModified = true;
                        DB.Entry(school).Property(s => s.features.studentDorms).IsModified = true;
                        DB.Entry(school).Property(s => s.features.uniqueFeature).IsModified = true;

                    }
                    

                    if (featuresImage != null && featuresImage.ContentLength > 0)
                    {

                        string path = "/content/images/uploads/schools/" + schoolID;
                        bool exists = Directory.Exists(Server.MapPath(path));
                        if (!exists)
                        {
                            Directory.CreateDirectory(Server.MapPath(path));
                        }

                        path = path + "/featuresImage" + Path.GetExtension(featuresImage.FileName);
                        featuresImage.SaveAs(Server.MapPath(path));
                        school.featuresImage = path;
                        DB.Entry(school).Property(s => s.featuresImage).IsModified = true;
                    }

                    

                    DB.SaveChanges();
                }


                if (string.IsNullOrEmpty(callback))
                {
                    data.statusCode = (int)statusCodes.success;
                }
                else
                {
                    data.statusCode = (int)statusCodes.successRun;
                    data.callback = callback;
                }

                data.message = "school features updated";
                return Json(data);
            }
            catch (Exception ex)
            {
                data.statusCode = (int)statusCodes.fail;
                data.message = "Failed to update school features; " + ex.Message;
                return Json(data);
            }
        }
示例#5
0
        public ActionResult editSchoolGeneral(School school, string name, string callback, HttpPostedFileWrapper videoCover)
        {
            ajaxReturnData data = new ajaxReturnData();

            try
            {
                using (ApplicationDbContext DB = new ApplicationDbContext())
                {
                    

                    if (DB.Schools.Where(s => s.url == school.url && s.id != school.id).Any())
                    {
                        data.message = "url is already assigned to another school";
                        data.statusCode = (int)statusCodes.fail;
                    }
                    else{

                        school.addContent(DB, "name", name);

                        //school.id = schoolID;
                        school.features = new SchoolFeatures();


                        //attach school to database then only update fields that arent multilanguage
                        DB.Schools.Attach(school);
                        DB.Entry(school).State = EntityState.Unchanged;
                        DB.Entry(school).Property(s => s.type).IsModified = true;
                        DB.Entry(school).Property(s => s.url).IsModified = true;
                        DB.Entry(school).Property(s => s.previewVideo).IsModified = true;
                        DB.Entry(school).Property(s => s.video).IsModified = true;
                        DB.Entry(school).Property(s => s.address).IsModified = true;
                        DB.Entry(school).Property(s => s.googleMap).IsModified = true;

                        school.loadContent(DB);

                        



                        if (videoCover != null && videoCover.ContentLength > 0)
                        {

                            string path = "/content/images/uploads/schools/" + school.id;
                            bool exists = Directory.Exists(Server.MapPath(path));
                            if (!exists)
                            {
                                Directory.CreateDirectory(Server.MapPath(path));
                            }

                            path = path + "/cover" + Path.GetExtension(videoCover.FileName);
                            videoCover.SaveAs(Server.MapPath(path));
                            school.videoCover = path;
                            DB.Entry(school).Property(s => s.videoCover).IsModified = true;
                            DB.SaveChanges();
                        }
                        


                        if (string.IsNullOrEmpty(callback))
                        {
                            data.statusCode = (int)statusCodes.success;
                        }
                        else
                        {
                            data.statusCode = (int)statusCodes.successRun;
                            data.callback = callback;
                        }

                        data.message = "school '" + school.url + "' updated";
                    }
                    
                }

                return Json(data);

            }
            catch (Exception ex)
            {
                data.statusCode = (int)statusCodes.fail;
                data.message = "Failed to update school; " + ex.Message;
                return Json(data);
            }
        }