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

            try
            {
                var query = from a in _context.edu_class
                            where a.code == obj.code
                            select a;
                if (query.Count() == 0)
                {
                    edu_class obj1 = new edu_class();
                    obj1.code     = obj.code;
                    obj1.name     = obj.name;
                    obj1.idcrouse = obj.idcrouse;
                    //   obj1.Birthday = Convert.ToDateTime(obj.Birthday);
                    obj1.numberstudent = obj.numberstudent;
                    obj1.schoolstart   = obj.schoolstart;
                    obj1.schoolend     = obj.schoolend;
                    obj1.schoolday     = obj.schoolday;
                    obj1.status        = obj.status;


                    obj1.classroom_id = obj.classroom_id;
                    obj1.teacher_id   = obj.teacher_id;
                    obj1.fee          = obj.fee;
                    obj1.datestart    = obj.datestart;
                    obj1.dateend      = obj.dateend;

                    obj1.sale_off_price = obj.sale_off_price;
                    obj1.start_sale_off = obj.start_sale_off;
                    obj1.end_sale_off   = obj.end_sale_off;
                    obj1.sale_off_note  = obj.sale_off_note;
                    obj1.location_id    = obj.location_id;


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

                    _context.edu_class.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));
        }
Beispiel #2
0
        public JsonResult update([FromBody] edu_class obj)
        {
            var msg = new JMessage()
            {
                Error = true
            };

            try
            {
                var rs = _context.edu_class.SingleOrDefault(x => x.id == obj.id);
                if (rs != null)
                {
                    rs.id          = obj.id;
                    rs.code        = obj.code;
                    rs.name        = obj.name;
                    rs.idcrouse    = obj.idcrouse;
                    rs.updatetime  = DateTime.Now;
                    rs.schoolstart = obj.schoolstart;
                    rs.userid      = obj.userid;

                    rs.schoolend = obj.schoolend;

                    rs.schoolday = obj.schoolday;
                    rs.status    = obj.status;


                    rs.classroom_id = obj.classroom_id;
                    rs.teacher_id   = obj.teacher_id;
                    rs.fee          = obj.fee;
                    rs.datestart    = obj.datestart;

                    rs.dateend        = obj.dateend;
                    rs.sale_off_price = obj.sale_off_price;

                    rs.start_sale_off = obj.start_sale_off;

                    rs.end_sale_off  = obj.end_sale_off;
                    rs.sale_off_note = obj.sale_off_note;
                    rs.location_id   = obj.location_id;


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