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);
        }
        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);
            }
        }
        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);
            }
        }