예제 #1
0
        public JsonResult insert([FromBody] edu_student obj)
        {
            var msg = new JMessage()
            {
                Error = false
            };

            try
            {
                edu_student obj1 = new edu_student();
                obj1.facebook = obj.facebook;
                obj1.sky      = obj.sky;
                obj1.google   = obj.google;
                //   obj1.Birthday = Convert.ToDateTime(obj.Birthday);
                obj1.twitter   = obj.twitter;
                obj1.wordpress = obj.wordpress;
                obj1.other     = obj.other;

                obj1.flag = 1;

                obj1.createtime = DateTime.Now;

                _context.edu_student.Add(obj1);
                _context.SaveChanges();
                msg.Title = "Thêm thành công";
            }
            catch (Exception ex)
            {
                msg.Error  = true;
                msg.Object = ex;
                msg.Title  = "Có lỗi khi thêm ";
            }
            return(Json(msg));
        }
예제 #2
0
        public JsonResult insert([FromBody] test obj)
        {
            var msg = new JMessage()
            {
                Error = false
            };

            try
            {
                var query = from a in _context.edu_student
                            where a.code == obj.code
                            select a;
                if (query.Count() == 0)
                {
                    edu_student obj1 = new edu_student();
                    obj1.code      = obj.code;
                    obj1.firstname = obj.firstname;
                    obj1.sex       = obj.sex;
                    //   obj1.Birthday = Convert.ToDateTime(obj.Birthday);
                    obj1.birthday   = obj.birthday;
                    obj1.flag       = 1;
                    obj1.createtime = DateTime.Now;
                    _context.edu_student.Add(obj1);
                    _context.SaveChanges();


                    edu_student_contact obj2 = new edu_student_contact();
                    var rs = _context.edu_student.OrderByDescending("id").FirstOrDefault();
                    obj2.studentID    = rs.id;
                    obj2.flag         = 1;
                    obj2.relationship = obj.relationship;
                    obj2.name         = obj.name;
                    _context.edu_student_contact.Add(obj2);

                    _context.SaveChanges();
                    msg.Title = "Thêm thành công";
                }
                else
                {
                    msg.Error = true;
                    msg.Title = "Mã đã tồn tại";
                }
            }
            catch (Exception ex)
            {
                msg.Error  = true;
                msg.Object = ex;
                msg.Title  = "Có lỗi khi thêm ";
            }
            return(Json(msg));
        }
예제 #3
0
        public JsonResult update([FromBody] edu_student obj)
        {
            var msg = new JMessage()
            {
                Error = true
            };

            try
            {
                var rs = _context.edu_student.SingleOrDefault(x => x.id == obj.id);
                if (rs != null)
                {
                    rs.id         = obj.id;
                    rs.facebook   = obj.facebook;
                    rs.sky        = obj.sky;
                    rs.google     = obj.google;
                    rs.updatetime = DateTime.Now;
                    rs.twitter    = obj.twitter;
                    rs.wordpress  = obj.wordpress;

                    rs.other = obj.other;



                    _context.edu_student.Update(rs);

                    _context.SaveChanges();
                    msg.Title = "Cập nhật thông tin thành công";
                    msg.Error = false;
                }
            }
            catch (Exception ex)
            {
                msg.Object = ex;
                msg.Title  = "Có lỗi khi cập nhật";
            }
            return(Json(msg));
        }