Пример #1
0
        // PUT: api/NguoiQuanLyGT/5
        public IHttpActionResult Put(int id, NguoiQuanLyGT nguoiQuanLyGT)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Not a valid model"));
            }

            using (var ctx = new GTVTContext())
            {
                var existingNguoiQuanLyGT = ctx.NguoiQuanLyGTs.Where(s => s.Id == id)
                                            .FirstOrDefault <NguoiQuanLyGT>();

                if (existingNguoiQuanLyGT != null)
                {
                    existingNguoiQuanLyGT.Ten      = nguoiQuanLyGT.Ten;
                    existingNguoiQuanLyGT.NgaySinh = nguoiQuanLyGT.NgaySinh;
                    existingNguoiQuanLyGT.Username = nguoiQuanLyGT.Username;
                    existingNguoiQuanLyGT.Password = nguoiQuanLyGT.Password;
                    ctx.SaveChanges();
                }
                else
                {
                    return(NotFound());
                }
            }

            return(Ok());
        }
Пример #2
0
 //POST: api/NguoiQuanLyGT
 public IHttpActionResult Post(NguoiQuanLyGT nguoiQuanLyGT)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     using (var ctx = new GTVTContext())
     {
         ctx.NguoiQuanLyGTs.Add(new NguoiQuanLyGT()
         {
             Ten      = nguoiQuanLyGT.Ten,
             NgaySinh = nguoiQuanLyGT.NgaySinh,
             Username = nguoiQuanLyGT.Username,
             Password = nguoiQuanLyGT.Password,
         });
         //ctx.NguoiQuanLyGTs.Add(nguoiQuanLyGT);
         ctx.SaveChanges();
     }
     return(Ok());
 }