コード例 #1
0
        public ActionResult Create(opr.Models.school school, FormCollection form)
        {
            //if (Request["Campus"] == null)
            //{
            //    return Json(new { message = "Please select at least one campus to continue", type = "error" });
            //}
            //string campus = Request["Campus"];
            //string[] ids = campus.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            //foreach (var id in ids)
            //{
            //    school.school_campus.Add(new opr.Models.school_campus() { CampusID = int.Parse(id) });
            //}
            //int sid = SchoolModel.Add(school);
            //if (sid > 0)
            //{
            //    return Json(new { message = "Successfully stored record to database.", type = "success" });
            //    //return JavaScript("window.location='" + Url.Action("SchoolConfig", "Schools", new { area = "Admin",id=sid }) + "'");
            //}
            //else if (sid == -1)
            //{
            //    return Json(new { message = "School name already regstered", type = "error" });

            //}
            //else if (sid == -2)
            //{
            //    return Json(new { message = "Username already registered", type = "error" });

            //}
            return(Json(new { message = "unable to store data. please view the log file or contact admin.", type = "error" }));
        }
コード例 #2
0
 public int Edit(school s)
 {
     s.LastEditedBy          = Helpers.CurrentUser.UserID;
     s.LastEditedOn          = DateTime.Now;
     database.Entry(s).State = System.Data.Entity.EntityState.Detached;
     database.Entry(s).State = System.Data.Entity.EntityState.Modified;
     return(SaveChanges());
 }
コード例 #3
0
        public int Update(opr.Models.school s)
        {
            var old = database.schools.Where(w => w.ID == s.ID).FirstOrDefault();

            //database.Entry(old).State = System.Data.Entity.EntityState.Detached;
            //database.Entry(s).State = System.Data.Entity.EntityState.Modified;

            if (s.Pasword == null)
            {
                s.Pasword = old.Pasword;
            }

            if (s.UserName == null)
            {
                s.UserName = old.UserName;
            }
            old.Address      = s.Address;
            old.Contact      = s.Contact;
            old.Email        = s.Email;
            old.LastEditedBy = Helpers.CurrentUser.UserID;
            s.LastEditedOn   = DateTime.Now;
            old.Mobile       = s.Mobile;
            old.Name         = s.Name;
            old.Princepal    = s.Princepal;
            old.UserID       = s.UserID;
            if (string.IsNullOrEmpty(s.Website))
            {
                old.Website = "";
            }
            else
            {
                old.Website = s.Website;
            }
            s.LastEditedBy = Helpers.CurrentUser.UserID;
            s.LastEditedOn = DateTime.Now;
            old.IsExpired  = s.IsExpired;
            old.IsActive   = s.IsActive;
            old.Logo       = s.Logo;
            foreach (var c in s.school_campus)
            {
                old.school_campus.Add(c);
            }

            return(SaveChanges());
        }
コード例 #4
0
        public int Add(opr.Models.school s)
        {
            school schol = database.schools.Where(w => w.Name == s.Name).FirstOrDefault();

            if (schol != null)
            {
                return(-1);
            }
            schol = null;
            schol = database.schools.Where(w => w.UserName == s.UserName).FirstOrDefault();  //check if school with same username exist
            var user = database.users.Where(w => w.UserName == s.UserName).FirstOrDefault(); // check if users with same user exist

            if (schol != null || user != null)
            {
                return(-2);
            }

            s.UserID       = Helpers.CurrentUser.UserID;
            s.LastEditedBy = Helpers.CurrentUser.UserID;
            s.LastEditedOn = DateTime.Now;
            s.Address      = string.IsNullOrEmpty(s.Address) ? string.Empty : s.Address;
            s.Contact      = string.IsNullOrEmpty(s.Contact) ? string.Empty : s.Contact;
            s.Email        = string.IsNullOrEmpty(s.Email) ? string.Empty : s.Email;
            s.Mobile       = string.IsNullOrEmpty(s.Mobile) ? string.Empty : s.Mobile;
            s.Princepal    = string.IsNullOrEmpty(s.Princepal) ? string.Empty : s.Princepal;
            s.Website      = string.IsNullOrEmpty(s.Website) ? string.Empty : s.Website;

            database.schools.Add(s);
            if (SaveChanges() > 0)
            {
                return(s.ID);
            }
            else
            {
                return(0);
            }
        }
コード例 #5
0
        public school GetByID(int id)
        {
            school s = database.schools.FirstOrDefault(a => a.ID == id);

            return(s);
        }
コード例 #6
0
        public bool Delete(int id)
        {
            school s = database.schools.FirstOrDefault(a => a.ID == id);

            return(SaveChanges() > 0);
        }