コード例 #1
0
        public JsonResult insert([FromBody] edu_schools obj)
        {
            var msg = new JMessage()
            {
                Error = false
            };

            try
            {
                var query = from a in _context.edu_schools
                            where a.code == obj.code
                            select a;
                if (query.Count() == 0)
                {
                    edu_schools obj1 = new edu_schools();
                    obj1.code = obj.code;
                    obj1.name = obj.name;
                    obj1.city = obj.city;
                    //   obj1.Birthday = Convert.ToDateTime(obj.Birthday);
                    obj1.level    = obj.level;
                    obj1.address  = obj.address;
                    obj1.country  = obj.country;
                    obj1.district = obj.district;

                    obj1.flag      = 1;
                    obj1.creattime = DateTime.Now;

                    _context.edu_schools.Add(obj1);
                    _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));
        }
コード例 #2
0
        public JsonResult update([FromBody] edu_schools obj)
        {
            var msg = new JMessage()
            {
                Error = true
            };

            try
            {
                var rs = _context.edu_schools.SingleOrDefault(x => x.id == obj.id);
                if (rs != null)
                {
                    rs.id         = obj.id;
                    rs.code       = obj.code;
                    rs.name       = obj.name;
                    rs.city       = obj.city;
                    rs.updatetime = DateTime.Now;
                    rs.level      = obj.level;
                    rs.address    = obj.address;

                    rs.country = obj.country;

                    rs.district = obj.district;



                    _context.edu_schools.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));
        }