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

            try
            {
                var rs = _context.common_properties.SingleOrDefault(x => x.id == obj.id);
                if (rs != null)
                {
                    rs.id        = obj.id;
                    rs.code      = obj.code;
                    rs.value     = obj.value;
                    rs.parent_id = obj.parent_id;
                    //rs.updatetime = DateTime.Now;
                    rs.order = obj.order;



                    _context.common_properties.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));
        }
コード例 #2
0
        public JsonResult insert([FromBody] common_properties obj)
        {
            var msg = new JMessage()
            {
                Error = false
            };

            try
            {
                var query = from a in _context.common_properties
                            where a.code == obj.code
                            select a;
                if (query.Count() == 0)
                {
                    common_properties obj1 = new common_properties();
                    obj1.code = "InformationSUMMIT_" + obj.code;

                    obj1.value     = obj.value;
                    obj1.parent_id = obj.parent_id;
                    //   obj1.Birthday = Convert.ToDateTime(obj.Birthday);
                    obj1.order = obj.order;


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

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