示例#1
0
        public void EditImage()
        {
            tndaEntities  db   = new tndaEntities();
            List <Person> list = db.People.ToList();
            string        id   = Request.QueryString["query"];
            string        img  = Request.QueryString["query"];

            foreach (Person p in list)
            {
                if (p.ID == int.Parse(id))
                {
                    p.Image = img;
                    db.SaveChanges();
                }
            }
        }
示例#2
0
        public Response changePassword(int personId, string oldPass, string newPass)
        {
            Response res = new Response
            {
                success = false,
                message = ""
            };

            using (DbContextTransaction transaction = db.Database.BeginTransaction())
            {
                try
                {
                    List <ACC> accs = db.ACCs.Where(a => a.ID_Person == personId).ToList();
                    foreach (ACC acc in accs)
                    {
                        if (acc == null)
                        {
                            res.message = "ACCOUNT_NOT_EXITS";
                            return(res);
                        }
                        if (acc.Pwd.Trim() != oldPass)
                        {
                            res.message = "WRONG_CURRENT_PASSWORD";
                            return(res);
                        }
                        acc.Pwd = Tools.encodeBase64(newPass);
                    }
                    db.SaveChanges();
                    transaction.Commit();
                    res.success = true;
                    return(res);
                }
                catch (Exception e)
                {
                    res.success = false;
                    res.message = e.Message;
                    transaction.Rollback();
                    return(res);
                }
            }
        }
示例#3
0
        //[ValidateAntiForgeryToken]
        public ActionResult EditClass(FormCollection form)
        {
            tndaEntities db = new tndaEntities();
            int          id = int.Parse(form["child-id"]);
            Person       p  = db.People.Find(id);

            if (p != null)
            {
                Class newClass = db.Classes.Find(int.Parse(form["child-class"]));
                if (p.ID_role == 1 || p.ID_role == 2)
                {
                    if (newClass != null)
                    {
                        string tName = p.ChristianName + " " + p.FirstName + " " + p.Name;
                        newClass.teacher_names = tName;
                        if (p.ID_Class.HasValue)
                        {
                            Class oldClass = db.Classes.Find(p.ID_Class.Value);
                            oldClass.teacher_names = "";
                        }
                        p.ID_Class = int.Parse(form["child-class"]);
                    }
                }
                else if (p.ID_role == 4 || p.ID_role == 7)
                {
                    if (newClass != null)
                    {
                        newClass.students_count += 1;
                        if (p.ID_Class.HasValue)
                        {
                            Class oldClass = db.Classes.Find(p.ID_Class.Value);
                            oldClass.students_count -= 1;
                        }
                        p.ID_Class = int.Parse(form["child-class"]);
                    }
                }
                db.SaveChanges();
            }
            return(Redirect(form["current_location"].ToString()));
        }
示例#4
0
 public JsonResult setImg(FormCollection form)
 {
     try
     {
         int id = int.Parse(form["id"]);
         HttpPostedFileBase file = Request.Files[0];
         //
         string _FileName = Guid.NewGuid().ToString() + Path.GetExtension(file.FileName);
         string _path     = Path.Combine(Server.MapPath("~/img/upload"), _FileName);
         string result    = Tools.uploadAndResizeImg(file, _path, _FileName);
         //
         tndaEntities db = new tndaEntities();
         db.People.Find(id).Image = result;
         db.SaveChanges();
         return(Json(new { success = true }, JsonRequestBehavior.AllowGet));
     }
     catch (Exception e)
     {
         return(Json(new { success = false, message = e.Message }, JsonRequestBehavior.AllowGet));
     }
     //
 }
示例#5
0
        public bool ReportPerson(FormCollection form)
        {
            int          idOldPerson = int.Parse(Request.QueryString["query"]);
            tndaEntities db          = new tndaEntities();
            Person       p           = new Person
            {
                ChristianName = form["child-ch-name"],
                FirstName     = form["fa-fname"],
                Name          = form["fa-name"],
                Birth         = Convert.ToDateTime(form["child-birth"]), //
                Address       = form["child-address"],
                ID_Class      = int.Parse(form["child-class"]),
                //ID_Farmily = form["child-address"],
                ID_role = 1,
                //Image = "",
                Note       = "",
                Phone      = "",
                Status     = true,
                Gender     = bool.Parse(form["child-gender"]),
                CreateDate = DateTime.Now
            };

            db.People.Add(p);
            //return Json(form["child-class"], JsonRequestBehavior.AllowGet);
            //db.People.Add(p);
            //db.SaveChanges();

            Report rp = new Report
            {
                ID_Person    = idOldPerson,
                ID_NewPerson = p.ID,
                Date         = DateTime.Now,
                Status       = 0
            };

            db.Reports.Add(rp);
            db.SaveChanges();
            return(true);
        }
示例#6
0
        //[ValidateAntiForgeryToken]
        public ActionResult DelPerson(FormCollection form)
        {
            tndaEntities db = new tndaEntities();
            Person       p  = db.People.Find(int.Parse(form["child-id"]));

            if (p != null)
            {
                if (p.ID_role == 1 || p.ID_role == 2)
                {
                    if (p.ID_Class != null)
                    {
                        Class c = db.Classes.Find(p.ID_Class);
                        c.teacher_names = null;
                    }
                }
                if (p.ID_role == 4 || p.ID_role == 7)
                {
                    if (p.ID_Class != null)
                    {
                        Class c = db.Classes.Find(p.ID_Class);
                        c.students_count -= 1;
                    }
                    if (p.ID_Farmily != null)
                    {
                        Family fam    = db.Families.Find(p.ID_Farmily);
                        Person father = db.People.Find(fam.ID_Dad);
                        Person mother = db.People.FirstOrDefault(per => per.ID_Farmily == fam.ID && per.ID != father.ID && per.ID != p.ID);
                        db.Families.Remove(fam);
                        db.People.Remove(father);
                        db.People.Remove(mother);
                    }
                }
                db.People.Remove(p);
                db.SaveChanges();
            }
            return(Redirect(form["current_location"].ToString()));
        }
示例#7
0
        public Response editPerson(FormCollection form)
        {
            int id = int.Parse(form["child-id"]);

            using (DbContextTransaction trans = db.Database.BeginTransaction())
            {
                try
                {
                    Person p = db.People.Find(id);
                    p.Name          = form.Get("child-name");
                    p.ChristianName = form.Get("child-ch-name");
                    try
                    {
                        p.Birth = Convert.ToDateTime(form.Get("child-birth"));
                    }
                    catch (Exception)
                    {
                        p.Birth = null;
                    }
                    p.FirstName  = form.Get("child-fname");
                    p.Address    = form.Get("child-address");
                    p.Gender     = bool.Parse(form["child-gender"]);
                    p.for_search = Tools.convert(p.ChristianName.Trim() + p.FirstName.Trim() + p.Name.Trim()).ToUpper().Replace(" ", String.Empty);

                    if (p.ID_role == 4 || p.ID_role == 7)
                    {
                        int fa_id = int.Parse(form["fa-id"]);
                        int mo_id = int.Parse(form["mo-id"]);
                        //
                        Person fP = db.People.Find(fa_id);
                        Person mP = db.People.Find(mo_id);
                        //
                        //fa
                        fP.ChristianName = form.Get("fa-ch-name");
                        fP.FirstName     = form.Get("fa-fname");
                        fP.Name          = form.Get("fa-name");
                        fP.Phone         = form.Get("fa-phone");
                        //mo
                        mP.ChristianName = form.Get("mo-ch-name");
                        mP.FirstName     = form.Get("mo-fname");
                        mP.Name          = form.Get("mo-name");
                        mP.Phone         = form.Get("mo-phone");
                    }
                    //save
                    db.SaveChanges();
                    trans.Commit();
                }
                catch (Exception e)
                {
                    trans.Rollback();
                    return(new Response()
                    {
                        success = false,
                        message = e.Message
                    });
                }
                return(new Response()
                {
                    success = true,
                });
            }
        }