예제 #1
0
        public IHttpActionResult Create(CreateSongModel model)
        {
            IHttpActionResult httpActionResult;

            if (string.IsNullOrEmpty(model.Name))
            {
                error.Add("Name is required");
            }
            if (error.errors.Count == 0)
            {
                Songs Songs = new Songs();
                Songs.UserId      = model.UserId;
                Songs.Name        = StandardString.StandardSongName(model.Name);
                Songs.KeyIds      = model.KeyIds;
                Songs.CreatedDate = model.CreatedDate;
                Songs             = db.Songs.Add(Songs);
                db.SaveChanges();
                httpActionResult = Ok(new SongsModel(Songs));
            }
            else
            {
                httpActionResult = new ErrorActionResult(Request, HttpStatusCode.BadRequest, error);
            }
            return(httpActionResult);
        }
예제 #2
0
        public IHttpActionResult CreateClass(CreateClassModel model)
        {
            IHttpActionResult httpActionResult;
            ErrorModel        error = new ErrorModel();

            if (string.IsNullOrEmpty(model.ClassId))
            {
                error.Add("Mã lớp là bắt buộc");
            }
            if (string.IsNullOrEmpty(model.ClassName))
            {
                error.Add("Tên lớp là bắt buộc");
            }
            if (_db.Teacher.FirstOrDefault(m => m.Id == model.Homeroom_Teacher) == null)
            {
                error.Add("Giáo viên không tồn tại");
            }
            if (error.Errors.Count == 0)
            {
                Class oneClass = new Class();
                oneClass.ClassName    = model.ClassName;
                oneClass.ClassId      = model.ClassId;
                oneClass.LearningTime = model.LearningTime;
                oneClass.Homeroom     = _db.Teacher.FirstOrDefault(m => m.Id == model.Homeroom_Teacher);
                oneClass = this._db.Class.Add(oneClass);
                this._db.SaveChanges();
                ClassModel viewModel = new ClassModel(oneClass);
                httpActionResult = Ok(viewModel);
            }
            else
            {
                httpActionResult = new ErrorActionResult(Request, System.Net.HttpStatusCode.BadRequest, error);
            }
            return(httpActionResult);
        }
예제 #3
0
        public async Task <IHttpActionResult> Create(CreateBillModel model)
        {
            IHttpActionResult httpActionResult;

            if (CheckPhoneNumber.CheckCorrectPhoneNumber(model.BuyerPhone))
            {
                error.Add("Vui lòng nhập đúng sdt!");
                httpActionResult = new ErrorActionResult(Request, HttpStatusCode.BadRequest, error);
            }
            if (error.errors.Count == 0 && CheckPhoneNumber.CheckCorrectPhoneNumber(model.BuyerPhone))
            {
                this._userManager = new ApplicationUserManager(new UserStore <Account>(this.db));

                Bill bill = new Bill();
                bill.BillCode = "HD" + RemoveSpacesAndSpecialCharacters.convertToUnSign(DateTime.Now.Date.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString());
                bill.Account  = await _userManager.FindByNameAsync(User.Identity.Name);

                bill.Branch        = db.Branches.FirstOrDefault(x => x.Id == model.BranchId);
                bill.CreatedDate   = DateTime.Now;
                bill.CreatedBy     = User.Identity.Name;
                bill.BuyerName     = model.BuyerName ?? model.BuyerName;
                bill.BuyerAddress  = model.BuyerAddress ?? model.BuyerAddress;
                bill.BuyerPhone    = model.BuyerPhone ?? model.BuyerPhone;
                bill.ModeOfPayment = model.ModeOfPayment ?? model.ModeOfPayment;
                bill = db.Bills.Add(bill);
                db.SaveChanges();
                httpActionResult = Ok(new BillModel(bill));
            }
            else
            {
                httpActionResult = new ErrorActionResult(Request, HttpStatusCode.BadRequest, error);
            }
            return(httpActionResult);
        }
예제 #4
0
        public IHttpActionResult TaoGV(TaoGV model)
        {
            IHttpActionResult httpActionResult;
            ErrorModel        error = new ErrorModel();

            if (string.IsNullOrEmpty(model.MaGV))
            {
                error.Add("Mã giáo viên không được để trống");
            }

            if (string.IsNullOrEmpty(model.TenGV))
            {
                error.Add("Họ tên giáo viên không được để trống");
            }

            if (error.Errors.Count == 0)
            {
                Teacher teacher = new Teacher();
                teacher.MaGV  = model.MaGV;
                teacher.TenGV = model.TenGV;
                teacher       = _db.GiaoVien.Add(teacher);

                _db.SaveChanges();
                TeacherModel vienModel = new TeacherModel(teacher);
                httpActionResult = Ok(vienModel);
            }
            else
            {
                httpActionResult = Ok(error);
            }

            return(httpActionResult);
        }
예제 #5
0
        public IHttpActionResult Create(CreateTeacherModel model)
        {
            IHttpActionResult httpActionResult;
            ErrorModel        errors = new ErrorModel();

            if (string.IsNullOrEmpty(model.MaGV))
            {
                errors.Add("Mã giáo viên là trường bắt buộc");
            }

            if (string.IsNullOrEmpty(model.TenGV))
            {
                errors.Add("Tên giáo viên là trường bắt buộc");
            }

            if (errors.Errors.Count == 0)
            {
                Teacher gv = new Teacher();
                gv.MaGV  = model.MaGV;
                gv.TenGV = model.TenGV;
                gv       = _db.Teacher.Add(gv);

                this._db.SaveChanges();

                TeacherModel viewModel = new TeacherModel(gv);

                httpActionResult = Ok(viewModel);
            }
            else
            {
                httpActionResult = new ErrorActionResult(Request, System.Net.HttpStatusCode.BadRequest, errors);
            }

            return(httpActionResult);
        }
예제 #6
0
        public IHttpActionResult TaoSV(TaoSV SV)
        {
            IHttpActionResult httpActionResult;
            ErrorModel        error = new ErrorModel();

            if (string.IsNullOrEmpty(SV.StudentName))
            {
                error.Add("Họ tên là bắt buộc");
            }
            if (string.IsNullOrEmpty(SV.StudentAddress))
            {
                error.Add("Địa chỉ là bắt buộc");
            }
            if (error.Errors.Count == 0)
            {
                Student sv = new Student();
                sv.TenSV  = SV.StudentName;
                sv.DiaChi = SV.StudentAddress;
                sv.NTNS   = SV.StudentBirth;
                sv.MaSV   = SV.StudentId;
                sv.Lop    = _db.Lop.FirstOrDefault(x => x.Id == SV.Class_Id);
                sv        = this._db.SinhVien.Add(sv);
                this._db.SaveChanges();
                StudentModel viewModel = new StudentModel(sv);
                httpActionResult = Ok(viewModel);
            }
            else
            {
                httpActionResult = Ok(error);
            }
            return(httpActionResult);
        }
        public IHttpActionResult CreateTeacher(CreateTeacherModel model)
        {
            IHttpActionResult httpActionResult;
            ErrorModel        error = new ErrorModel();

            if (string.IsNullOrEmpty(model.TeacherId))
            {
                error.Add("Mã giáo viên không được để trống");
            }

            if (string.IsNullOrEmpty(model.TeacherName))
            {
                error.Add("Họ tên giáo viên không được để trống");
            }

            if (error.Errors.Count == 0)
            {
                Teacher teacher = new Teacher();
                teacher.TeacherId      = model.TeacherId;
                teacher.TeacherName    = model.TeacherName;
                teacher.TeacherAddress = model.TeacherAddress;
                teacher = _db.Teacher.Add(teacher);

                _db.SaveChanges();
                TeacherModel vienModel = new TeacherModel(teacher);
                httpActionResult = Ok(vienModel);
            }
            else
            {
                httpActionResult = new ErrorActionResult(Request, System.Net.HttpStatusCode.BadRequest, error);
            }

            return(httpActionResult);
        }
예제 #8
0
        public IHttpActionResult TaoLop(TaoLop lop)
        {
            IHttpActionResult httpActionResult;
            ErrorModel        error = new ErrorModel();

            if (string.IsNullOrEmpty(lop.MaLop))
            {
                error.Add("Mã lớp bắt buộc");
            }
            if (string.IsNullOrEmpty(lop.TenLop))
            {
                error.Add("Tên lớp bắt buộc");
            }
            if (_db.GiaoVien.FirstOrDefault(m => m.Id == lop.ChuNhiem) == null)
            {
                error.Add("Giáo viên không tồn tại");
            }
            if (error.Errors.Count == 0)
            {
                Class oneClass = new Class();
                oneClass.TenLop   = lop.TenLop;
                oneClass.MaLop    = lop.MaLop;
                oneClass.LichDay  = lop.LichDay;
                oneClass.ChuNhiem = _db.GiaoVien.FirstOrDefault(m => m.Id == lop.ChuNhiem);
                oneClass          = this._db.Lop.Add(oneClass);
                this._db.SaveChanges();
                ClassModel viewModel = new ClassModel(oneClass);
                httpActionResult = Ok(viewModel);
            }
            else
            {
                httpActionResult = Ok(error);
            }
            return(httpActionResult);
        }
예제 #9
0
        public IHttpActionResult TaoGiangVien(CreateGVModel model)
        {
            IHttpActionResult httpActionResult;
            ErrorModel        errors = new ErrorModel();

            if (string.IsNullOrEmpty(model.Ma))
            {
                errors.Add("Mã giảng viên là trường bắt buộc");
            }

            if (string.IsNullOrEmpty(model.Ten))
            {
                errors.Add("Tên giảng viên là trường bắt buộc");
            }

            if (errors.Errors.Count == 0)
            {
                GiangVien GV = new GiangVien();
                GV.Ma  = model.Ma;
                GV.Ten = model.Ten;
                GV     = _db.GiangViens.Add(GV);

                this._db.SaveChanges();

                GiangVienModel viewModel = new GiangVienModel(GV);

                httpActionResult = Ok(viewModel);
            }
            else
            {
                httpActionResult = Ok(errors);
            }

            return(httpActionResult);
        }
        public IHttpActionResult CreateStudent(CreateStudentModel model)
        {
            IHttpActionResult httpActionResult;
            ErrorModel        error = new ErrorModel();

            if (string.IsNullOrEmpty(model.StudentName))
            {
                error.Add("Họ tên là bắt buộc!");
            }
            if (string.IsNullOrEmpty(model.StudentAddress))
            {
                error.Add("Địa chỉ là bắt buộc!");
            }
            if (error.Errors.Count == 0)
            {
                Student sv = new Student();
                sv.StudentName    = model.StudentName;
                sv.StudentAddress = model.StudentAddress;
                sv.StudentBirth   = model.StudentBirth;
                sv.StudentId      = model.StudentId;
                sv.Class          = _db.Class.FirstOrDefault(x => x.Id == model.Class_Id);
                sv = this._db.Student.Add(sv);
                this._db.SaveChanges();
                StudentModel viewModel = new StudentModel(sv);
                httpActionResult = Ok(viewModel);
            }
            else
            {
                httpActionResult = new ErrorActionResult(Request, System.Net.HttpStatusCode.BadRequest, error);
            }
            return(httpActionResult);
        }
예제 #11
0
        public IHttpActionResult TaoGV(TaoGiaoVien model)
        {
            IHttpActionResult httpActionResult;
            ErrorModel        errors = new ErrorModel();

            if (string.IsNullOrEmpty(model.MaGv))
            {
                errors.Add("Mã giao vien là trường bắt buộc");
            }

            if (errors.Errors.Count == 0)
            {
                TTGV gv = new TTGV();
                gv.MaGv     = model.MaGv;
                gv.HoTen    = model.HoTen;
                gv.NgaySinh = model.NgaySinh;

                gv = db.TTGVs.Add(gv);

                this.db.SaveChanges();

                GiaoVien_model Lopm = new GiaoVien_model(gv);

                httpActionResult = Ok(Lopm);
            }
            else
            {
                httpActionResult = new ErrorActionResult(Request, System.Net.HttpStatusCode.BadRequest, errors);
            }

            return(httpActionResult);
        }
예제 #12
0
        public IHttpActionResult GetByCode(int code)
        {
            IHttpActionResult httpActionResult;
            Branch            branch = db.Branches.FirstOrDefault(x => x.Id == code);

            if (branch == null)
            {
                error.Add("Not Found");
                httpActionResult = new ErrorActionResult(Request, HttpStatusCode.NotFound, error);
            }
            else
            {
                httpActionResult = Ok(new BranchModel(branch));
            }
            return(httpActionResult);
        }
        public IHttpActionResult TaoLop(CreateClassModel model)
        {
            IHttpActionResult httpActionResult;
            ErrorModel        errors = new ErrorModel();

            if (string.IsNullOrEmpty(model.MaLop))
            {
                errors.Add("Mã lớp là trường bắt buộc!");
            }

            if (errors.Errors.Count == 0)
            {
                Lop lop = new Lop();
                lop.MaLop  = model.MaLop;
                lop.TenLop = model.TenLop;
                //lop.GVCN_ID = model.GVCN_ID;
                lop = _db.Lops.Add(lop);

                this._db.SaveChanges();

                LopModel viewModel = new LopModel(lop);

                httpActionResult = Ok(viewModel);
            }
            else
            {
                httpActionResult = Ok(errors);
            }

            return(httpActionResult);
        }
예제 #14
0
        public IHttpActionResult TaoLop(TaoLop tl)
        {
            IHttpActionResult httpActionResult;
            ErrorModel        errors = new ErrorModel();

            if (string.IsNullOrEmpty(tl.MaLop))
            {
                errors.Add("Mã lớp là trường bắt buộc");
            }

            if (errors.Errors.Count == 0)
            {
                TTLOP lop = new TTLOP();
                lop.MaLop  = tl.MaLop;
                lop.TenLop = tl.TenLop;
                lop.gvcn   = db.TTGVs.FirstOrDefault(x => x.Id == tl.gvcnId);

                lop = db.TTLOPs.Add(lop);

                this.db.SaveChanges();

                Lop_model Lopm = new Lop_model(lop);

                httpActionResult = Ok(Lopm);
            }
            else
            {
                httpActionResult = new ErrorActionResult(Request, System.Net.HttpStatusCode.BadRequest, errors);
            }

            return(httpActionResult);
        }
예제 #15
0
        public IHttpActionResult CapNhatLop(CapNhatLop model)
        {
            IHttpActionResult httpActionResult;
            ErrorModel        errors = new ErrorModel();

            TTLOP lop = this.db.TTLOPs.FirstOrDefault(x => x.Id == model.Id);

            if (lop == null)
            {
                errors.Add("Không tìm thấy lớp");

                httpActionResult = new ErrorActionResult(Request, System.Net.HttpStatusCode.NotFound, errors);
            }
            else
            {
                lop.MaLop = model.MaLop ?? model.MaLop;

                lop.TenLop = model.TenLop ?? model.TenLop;

                lop.gvcn = db.TTGVs.FirstOrDefault(x => x.Id == model.gvcnId);

                this.db.Entry(lop).State = System.Data.Entity.EntityState.Modified;

                this.db.SaveChanges();

                httpActionResult = Ok(new Lop_model(lop));
            }

            return(httpActionResult);
        }
예제 #16
0
        public IHttpActionResult GetByCode(string code)
        {
            IHttpActionResult httpActionResult;
            Product           product = db.Products.FirstOrDefault(x => x.ProductCode == code);

            if (product == null)
            {
                error.Add("Not Found");
                httpActionResult = new ErrorActionResult(Request, HttpStatusCode.NotFound, error);
            }
            else
            {
                httpActionResult = Ok(new ProductModel(product));
            }
            return(httpActionResult);
        }
예제 #17
0
        public IHttpActionResult TaoSV(TaoSinhVien model)
        {
            IHttpActionResult httpActionResult;
            ErrorModel        errors = new ErrorModel();

            if (string.IsNullOrEmpty(model.MaSv))
            {
                errors.Add("Mã sinh vien là trường bắt buộc");
            }

            if (errors.Errors.Count == 0)
            {
                TTSV sv = new TTSV();
                sv.MaSv     = model.MaSv;
                sv.HoTen    = model.HoTen;
                sv.NgaySinh = model.NgaySinh;
                sv.lop      = db.TTLOPs.FirstOrDefault(x => x.Id == model.LopId);
                sv          = db.TTSVs.Add(sv);

                this.db.SaveChanges();

                SinhVien_model SV = new SinhVien_model(sv);

                httpActionResult = Ok(SV);
            }
            else
            {
                // httpActionResult = Ok(errors);
                httpActionResult = new ErrorActionResult(Request, System.Net.HttpStatusCode.BadRequest, errors);
            }

            return(httpActionResult);
        }
예제 #18
0
        public IHttpActionResult Update(UpdateTeacherModel model)
        {
            IHttpActionResult httpActionResult;
            ErrorModel        errors = new ErrorModel();

            Teacher gv = this._db.Teacher.FirstOrDefault(x => x.Id == model.Id);

            if (gv == null)
            {
                errors.Add("Không tìm thấy giáo viên này");
                httpActionResult = new ErrorActionResult(Request, System.Net.HttpStatusCode.NotFound, errors);
            }
            else
            {
                gv.MaGV  = model.MaGV ?? model.MaGV;
                gv.TenGV = model.TenGV ?? model.TenGV;
                this._db.Entry(gv).State = System.Data.Entity.EntityState.Modified;

                this._db.SaveChanges();

                httpActionResult = Ok(new TeacherModel(gv));
            }

            return(httpActionResult);
        }
예제 #19
0
        public IHttpActionResult CapNhatGiangVien(UpdateGVModel model)
        {
            IHttpActionResult httpActionResult;
            ErrorModel        errors = new ErrorModel();

            GiangVien GV = this._db.GiangViens.FirstOrDefault(x => x.Id == model.Id);

            if (GV == null)
            {
                errors.Add("Không tìm thấy giảng viên có ID này");

                httpActionResult = Ok(errors);
            }
            else
            {
                GV.Ma  = model.Ma ?? model.Ma;
                GV.Ten = model.Ten ?? model.Ten;

                this._db.Entry(GV).State = System.Data.Entity.EntityState.Modified;

                this._db.SaveChanges();

                httpActionResult = Ok(new GiangVienModel(GV));
            }

            return(httpActionResult);
        }
예제 #20
0
        public IHttpActionResult Update(UpdateClassModel model)
        {
            IHttpActionResult httpActionResult;
            ErrorModel        errors = new ErrorModel();

            Classes lop = this._db.Class.FirstOrDefault(x => x.Id == model.Id);

            if (lop == null)
            {
                errors.Add("Không tìm thấy lớp");

                httpActionResult = new ErrorActionResult(Request, System.Net.HttpStatusCode.NotFound, errors);
            }
            else
            {
                lop.Malop                 = model.MaLop ?? model.MaLop;
                lop.Tenlop                = model.TenLop ?? model.TenLop;
                lop.GiaoVienChuNhiem      = _db.Teacher.FirstOrDefault(m => m.Id == model.GVCN_Id);
                this._db.Entry(lop).State = System.Data.Entity.EntityState.Modified;

                this._db.SaveChanges();

                httpActionResult = Ok(new ClassModel(lop));
            }

            return(httpActionResult);
        }
예제 #21
0
        public IHttpActionResult GetById(long id)
        {
            IHttpActionResult httpActionResult;
            Lop lop = db.Lops.FirstOrDefault(x => x.Id == id);

            if (lop == null)
            {
                err.Add("Không tìm thấy lớp yêu cầu");
                httpActionResult = Ok(err);
            }
            else
            {
                httpActionResult = Ok(new LopModel(lop));
            }
            return(httpActionResult);
        }
예제 #22
0
        public IHttpActionResult CapNhatSV(UpdateStudentModel model)
        {
            IHttpActionResult httpActionResult;
            ErrorModel        errors = new ErrorModel();

            Student sv = this._db.Students.FirstOrDefault(x => x.Id == model.Id);

            if (sv == null)
            {
                errors.Add("Không tìm th?y sv");

                httpActionResult = Ok(errors);
            }
            else
            {
                sv.MSSV   = model.MaSV ?? model.MaSV;
                sv.HoTen  = model.HoTenSV ?? model.HoTenSV;
                sv.DiaChi = model.DiaChi ?? model.DiaChi;

                this._db.Entry(sv).State = System.Data.Entity.EntityState.Modified;

                this._db.SaveChanges();

                httpActionResult = Ok(new StudentModel(sv));
            }

            return(httpActionResult);
        }
예제 #23
0
        public IHttpActionResult GVTheoId(long id)
        {
            IHttpActionResult httpActionResult;
            GiaoVien          giaoVien = db.GiaoViens.FirstOrDefault(x => x.Id == id);

            if (giaoVien == null)
            {
                err.Add("Không tìm thấy giáo viên");
                httpActionResult = new ErrorActionResult(Request, System.Net.HttpStatusCode.NotFound, err);
            }
            else
            {
                httpActionResult = Ok(new GiaoVienModel(giaoVien));
            }
            return(httpActionResult);
        }
예제 #24
0
        public IHttpActionResult CapNhatLop(UpdateClassModel model)
        {
            IHttpActionResult httpActionResult;
            ErrorModel        errors = new ErrorModel();

            Lop lop = this._db.Lops.FirstOrDefault(x => x.Id == model.Id);

            if (lop == null)
            {
                errors.Add("Không tìm thấy lớp");

                httpActionResult = Ok(errors);
            }
            else
            {
                lop.MaLop  = model.MaLop ?? model.MaLop;
                lop.TenLop = model.TenLop ?? model.TenLop;

                this._db.Entry(lop).State = System.Data.Entity.EntityState.Modified;

                this._db.SaveChanges();

                httpActionResult = Ok(new ClassModel(lop));
            }

            return(httpActionResult);
        }
예제 #25
0
        public IHttpActionResult GetById(long id)
        {
            IHttpActionResult httpActionResult;
            HocSinh           hs = db.HocSinhs.FirstOrDefault(x => x.Id == id);

            if (hs == null)
            {
                err.Add("Không tìm thấy học sinh yêu cầu");
                httpActionResult = Ok(err);
            }
            else
            {
                httpActionResult = Ok(new HocSinhModel(hs));
            }
            return(httpActionResult);
        }
예제 #26
0
        public IHttpActionResult Update(UpdateStudentModel model)
        {
            IHttpActionResult httpActionResult;
            ErrorModel        errors = new ErrorModel();

            Student sv = this._db.Students.FirstOrDefault(x => x.Id == model.Id);

            if (sv == null)
            {
                errors.Add("Không tìm thấy Sinh viên");

                httpActionResult = new ErrorActionResult(Request, System.Net.HttpStatusCode.NotFound, errors);
            }
            else
            {
                sv.HoTen    = model.HoTen ?? model.HoTen;
                sv.MSSV     = model.MSSV ?? model.MSSV;
                sv.NgaySinh = model.NgaySinh;
                sv.DiaChi   = model.DiaChi ?? model.DiaChi;
                sv.Class    = _db.Class.FirstOrDefault(m => m.Id == model.LOP_ID);
                this._db.Entry(sv).State = System.Data.Entity.EntityState.Modified;

                this._db.SaveChanges();

                httpActionResult = Ok(new StudentModel(sv));
            }

            return(httpActionResult);
        }
예제 #27
0
        public IHttpActionResult CapNhatGV(CapNhatGiaoVien model)
        {
            IHttpActionResult httpActionResult;
            ErrorModel        errors = new ErrorModel();

            TTGV gv = this.db.TTGVs.FirstOrDefault(x => x.Id == model.Id);

            if (gv == null)
            {
                errors.Add("Không tìm thấy lớp");

                httpActionResult = new ErrorActionResult(Request, System.Net.HttpStatusCode.NotFound, errors);
            }
            else
            {
                gv.MaGv     = model.MaGv ?? model.MaGv;
                gv.NgaySinh = model.NgaySinh;
                gv.HoTen    = model.HoTen ?? model.HoTen;

                this.db.Entry(gv).State = System.Data.Entity.EntityState.Modified;

                this.db.SaveChanges();

                httpActionResult = Ok(new GiaoVien_model(gv));
            }

            return(httpActionResult);
        }
예제 #28
0
        public IHttpActionResult TaoGV(CreateGiaoVienModel model)
        {
            IHttpActionResult httpActionResult;
            ErrorModel        errors = new ErrorModel();


            if (string.IsNullOrEmpty(model.TenGV))
            {
                errors.Add("Tên GV là bat buoc");
            }

            if (errors.Errors.Count == 0)
            {
                GiaoVien gv = new GiaoVien();
                gv.HoTen = model.TenGV;


                gv = _db.GiaoViens.Add(gv);

                this._db.SaveChanges();

                GiaoVienModel viewModel = new GiaoVienModel(gv);

                httpActionResult = Ok(viewModel);
            }
            else
            {
                httpActionResult = Ok(errors);
            }

            return(httpActionResult);
        }
        public IHttpActionResult GetById(long id)
        {
            IHttpActionResult httpActionResult;
            GiaoVien          giaoVien = db.GiaoViens.FirstOrDefault(x => x.Id == id);

            if (giaoVien == null)
            {
                err.Add("Không tìm thấy giáo viên");
                httpActionResult = Ok(err);
            }
            else
            {
                httpActionResult = Ok(new GiaoVienModel(giaoVien));
            }
            return(httpActionResult);
        }
예제 #30
0
        public IHttpActionResult CapNhatGV(UpdateGiaoVienModel model)
        {
            IHttpActionResult httpActionResult;
            ErrorModel        errors = new ErrorModel();

            GiaoVien gv = this._db.GiaoViens.FirstOrDefault(x => x.Id == model.Id);

            if (gv == null)
            {
                errors.Add("Không tìm thấy gv");

                httpActionResult = Ok(errors);
            }
            else
            {
                gv.HoTen = model.TenGV ?? model.TenGV;


                this._db.Entry(gv).State = System.Data.Entity.EntityState.Modified;

                this._db.SaveChanges();

                httpActionResult = Ok(new GiaoVienModel(gv));
            }

            return(httpActionResult);
        }