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

            using (var ctx = new GTVTContext())
            {
                var existingDenGT_ThayDoi = ctx.DenGT_ThayDois.Where(s => s.Id == id)
                                            .FirstOrDefault <DenGT_ThayDoi>();

                if (existingDenGT_ThayDoi != null)
                {
                    existingDenGT_ThayDoi.ThoiDiemThayDoi = denGT_ThayDoi.ThoiDiemThayDoi;
                    existingDenGT_ThayDoi.ThoiGianDoi     = denGT_ThayDoi.ThoiGianDoi;
                    existingDenGT_ThayDoi.Do_TD           = denGT_ThayDoi.Do_TD;
                    existingDenGT_ThayDoi.Vang_TD         = denGT_ThayDoi.Vang_TD;
                    existingDenGT_ThayDoi.Xanh_TD         = denGT_ThayDoi.Xanh_TD;
                    existingDenGT_ThayDoi.TuDong          = denGT_ThayDoi.TuDong;
                    // existingDenGT_ThayDoi.DenGiaoThong_Id = denGT_ThayDoi.DenGiaoThong_Id;
                    // existingDenGT_ThayDoi.NguoiQuanLyGT_Id = denGT_ThayDoi.NguoiQuanLyGT_Id;
                    ctx.SaveChanges();
                }
                else
                {
                    return(NotFound());
                }
            }

            return(Ok());
        }
        // PUT: api/Chuxe/5
        public HttpResponseMessage Put(int id, [FromBody] Chuxe chuxe)
        {
            try
            {
                using (GTVTContext context = new GTVTContext())
                {
                    var entity = context.Chuxes.FirstOrDefault(e => e.ChuxeId == id);
                    if (entity == null)
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.NotFound,
                                                           "Chu xe voi Id " + id.ToString() + " khong co de sua"));
                    }
                    else
                    {
                        entity.CMND     = chuxe.CMND;
                        entity.HoTen    = chuxe.HoTen;
                        entity.DiaChi   = chuxe.DiaChi;
                        entity.GioiTinh = chuxe.GioiTinh;
                        entity.NamSinh  = chuxe.NamSinh;
                        context.SaveChanges();

                        return(Request.CreateResponse(HttpStatusCode.OK, entity));
                    }
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
        }
        // PUT: api/DenGiaoThong/5
        public IHttpActionResult Put(int id, DenGiaoThong denGiaoThong)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Not a valid model"));
            }

            using (var ctx = new GTVTContext())
            {
                var existingDenGiaoThong = ctx.DenGiaoThongs.Where(s => s.Id == id)
                                           .FirstOrDefault <DenGiaoThong>();

                if (existingDenGiaoThong != null)
                {
                    existingDenGiaoThong.Do        = denGiaoThong.Do;
                    existingDenGiaoThong.Vang      = denGiaoThong.Vang;
                    existingDenGiaoThong.Xanh      = denGiaoThong.Xanh;
                    existingDenGiaoThong.TrangThai = denGiaoThong.TrangThai;
                    //existingDenGiaoThong.KhuVuc_Id = denGiaoThong.KhuVuc_Id;
                    existingDenGiaoThong.TenDuong = denGiaoThong.TenDuong;
                    ctx.SaveChanges();
                }
                else
                {
                    return(NotFound());
                }
            }

            return(Ok());
        }
Пример #4
0
        // PUT: api/Xe/5
        public HttpResponseMessage Put(int id, [FromBody] Xe xe)
        {
            try
            {
                using (GTVTContext context = new GTVTContext())
                {
                    var entity = context.Xes.FirstOrDefault(e => e.XeId == id);
                    if (entity == null)
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.NotFound,
                                                           "Xe voi Id " + id.ToString() + " khong co de sua"));
                    }
                    else
                    {
                        entity.BienSoXe  = xe.BienSoXe;
                        entity.Hang      = xe.Hang;
                        entity.Loai      = xe.Loai;
                        entity.MauSac    = xe.MauSac;
                        entity.Nam       = xe.Nam;
                        entity.TrangThai = xe.TrangThai;
                        entity.Chuxe     = xe.Chuxe;
                        context.SaveChanges();

                        return(Request.CreateResponse(HttpStatusCode.OK, entity));
                    }
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
        }
Пример #5
0
        // PUT: api/Banglai/5
        public HttpResponseMessage Put(int id, [FromBody] Banglai banglai)
        {
            try
            {
                using (GTVTContext context = new GTVTContext())
                {
                    var entity = context.Banglais.FirstOrDefault(e => e.BanglaiId == id);
                    if (entity == null)
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.NotFound,
                                                           "Bang lai voi Id " + id.ToString() + " khong co de sua"));
                    }
                    else
                    {
                        entity.LoaiBang = banglai.LoaiBang;
                        entity.ThongTin = banglai.ThongTin;

                        context.SaveChanges();

                        return(Request.CreateResponse(HttpStatusCode.OK, entity));
                    }
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
        }
        // PUT: api/KhuVuc/5
        public IHttpActionResult Put(int id, KhuVuc khuVuc)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Not a valid model"));
            }

            using (var ctx = new GTVTContext())
            {
                var existingKhuVuc = ctx.KhuVucs.Where(s => s.Id == id)
                                     .FirstOrDefault <KhuVuc>();

                if (existingKhuVuc != null)
                {
                    existingKhuVuc.TenKhuVuc = khuVuc.TenKhuVuc;

                    ctx.SaveChanges();
                }
                else
                {
                    return(NotFound());
                }
            }
            return(Ok());
        }
Пример #7
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());
        }
Пример #8
0
        //POST: api/DenGT_ThayDoi
        public IHttpActionResult Post(DenGT_ThayDoi denGT_ThayDoi)
        {
            DateTime today = DateTime.Now;

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            using (var ctx = new GTVTContext())
            {
                ctx.DenGT_ThayDois.Add(new DenGT_ThayDoi()
                {
                    ThoiDiemThayDoi  = denGT_ThayDoi.ThoiDiemThayDoi,
                    ThoiGianDoi      = denGT_ThayDoi.ThoiGianDoi,
                    Do_TD            = denGT_ThayDoi.Do_TD,
                    Vang_TD          = denGT_ThayDoi.Vang_TD,
                    Xanh_TD          = denGT_ThayDoi.Xanh_TD,
                    TuDong           = denGT_ThayDoi.TuDong,
                    ThoiGianThucHien = denGT_ThayDoi.ThoiGianThucHien,
                    DenGiaoThong_Id  = denGT_ThayDoi.DenGiaoThong_Id,
                    NguoiQuanLyGT_Id = denGT_ThayDoi.NguoiQuanLyGT_Id,
                });
                //ctx.DenGT_ThayDois.Add(denGT_ThayDoi);
                ctx.SaveChanges();
            }
            return(Ok());
        }
Пример #9
0
 // DELETE: api/Banglai/5
 public HttpResponseMessage Delete(int id)
 {
     try
     {
         using (GTVTContext context = new GTVTContext())
         {
             var entity = context.Banglais.FirstOrDefault(e => e.BanglaiId == id);
             if (entity == null)
             {
                 return(Request.CreateErrorResponse(HttpStatusCode.NotFound,
                                                    "Bang lai voi Id = " + id.ToString() + " khong co de xoa"));
             }
             else
             {
                 context.Banglais.Remove(entity);
                 context.SaveChanges();
                 return(Request.CreateResponse(HttpStatusCode.OK));
             }
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
     }
 }
 // POST: api/KhuVuc
 public IHttpActionResult Post(KhuVuc khuvuc)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     using (var ctx = new GTVTContext())
     {
         ctx.KhuVucs.Add(new KhuVuc()
         {
             TenKhuVuc = khuvuc.TenKhuVuc,
         });
         //ctx.KhuVucs.Add(khuvuc);
         ctx.SaveChanges();
     }
     return(Ok());
 }
Пример #11
0
 public IHttpActionResult Post(ViPhamLuatGT viPham)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     using (var ctx = new GTVTContext())
     {
         ctx.ViPhamLuatGTs.Add(new ViPhamLuatGT()
         {
             Id_BaoCao        = viPham.Id_BaoCao,
             Id_LuatGiaoThong = viPham.Id_LuatGiaoThong
         });
         ctx.SaveChanges();
     }
     return(Ok());
 }
        // POST: api/BaoCao
        //[HttpPost]
        public IHttpActionResult Post(BaoCao bc, List <ViPhamLuatGT> dsViPham)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            using (GTVTContext ctx = new GTVTContext())
            {
                var baocao = bc;
                bc.ViPhamLuatGTs = dsViPham;

                ctx.BaoCaos.Add(baocao);
                ctx.SaveChanges();
            }
            return(Ok());
        }
Пример #13
0
        // DELETE: api/DenGT_ThayDoi/5
        public IHttpActionResult Delete(int id)
        {
            if (id <= 0)
            {
                return(BadRequest("Not a valid student id"));
            }

            using (var ctx = new GTVTContext())
            {
                var DenGT_ThayDoi = ctx.DenGT_ThayDois
                                    .Where(s => s.Id == id)
                                    .FirstOrDefault();

                ctx.Entry(DenGT_ThayDoi).State = System.Data.Entity.EntityState.Deleted;
                ctx.SaveChanges();
            }

            return(Ok());
        }
Пример #14
0
 // POST: api/TinhTrangDuong
 public IHttpActionResult Post(TinhTrangDuong tinhTrangDuong)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     using (var ctx = new GTVTContext())
     {
         ctx.TinhTrangDuongs.Add(new TinhTrangDuong()
         {
             KhuVuc_Id = tinhTrangDuong.KhuVuc_Id,
             TenDuong  = tinhTrangDuong.TenDuong,
             TrangThai = tinhTrangDuong.TrangThai
         });
         //ctx.TinhTrangDuongs.Add(tinhTrangDuong);
         ctx.SaveChanges();
     }
     return(Ok());
 }
Пример #15
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());
 }
Пример #16
0
        // POST: api/Banglai
        public HttpResponseMessage Post([FromBody] Banglai banglai)
        {
            try
            {
                using (GTVTContext context = new GTVTContext())
                {
                    context.Banglais.Add(banglai);
                    context.SaveChanges();

                    var message = Request.CreateResponse(HttpStatusCode.Created, banglai);
                    message.Headers.Location = new Uri(Request.RequestUri +
                                                       banglai.BanglaiId.ToString());

                    return(message);
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
        }
        public void InsertChuxeXe(int ChuxeId, int XeId)
        {
            using (GTVTContext context = new GTVTContext())
            {
                Chuxe chuxe = new Chuxe {
                    ChuxeId = ChuxeId
                };
                context.Chuxes.Add(chuxe);
                context.Chuxes.Attach(chuxe);

                Xe xe = new Xe {
                    XeId = XeId
                };
                context.Xes.Add(xe);
                context.Xes.Attach(xe);

                chuxe.Xes = new List <Xe>();
                chuxe.Xes.Add(xe);
                context.SaveChanges();
            }
        }
 // POST: api/DenGiaoThong
 public IHttpActionResult Post(DenGiaoThong denGiaoThong)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     using (var ctx = new GTVTContext())
     {
         ctx.DenGiaoThongs.Add(new DenGiaoThong()
         {
             Do        = denGiaoThong.Do,
             Xanh      = denGiaoThong.Xanh,
             Vang      = denGiaoThong.Vang,
             TrangThai = denGiaoThong.TrangThai,
             KhuVuc_Id = denGiaoThong.KhuVuc_Id,
             TenDuong  = denGiaoThong.TenDuong
         });
         //ctx.DenGiaoThongs.Add(denGiaoThong);
         ctx.SaveChanges();
     }
     return(Ok());
 }
        public void InsertChuxeBanglai(int ChuxeId, int BanglaiId)
        {
            using (GTVTContext context = new GTVTContext())
            {
                var chuxe = new Chuxe {
                    ChuxeId = ChuxeId
                };
                //    context.Chuxes.Add(chuxe);
                //    context.Chuxes.Attach(chuxe);

                var banglai = new Banglai {
                    BanglaiId = BanglaiId
                };
                //    context.Banglais.Add(banglai);
                //    context.Banglais.Attach(banglai);
                var ChuxeBanglai = new ChuXevaBangLai
                {
                    ChuxeId   = chuxe.ChuxeId,
                    BanglaiId = banglai.BanglaiId
                };

                context.ChuXevaBangLais.Add(ChuxeBanglai);
                context.SaveChanges();

                //    chuxe.

                //context.SaveChanges();
                //GTVTContext context = new GTVTContext();
                //var cmdText = "sp_ThemTaixeBanglai @ChuxeId, @BanglaiId";
                //var sqlParams = new[]{
                //new SqlParameter("ChuxeId", ChuxeId),
                //new SqlParameter("BanglaiId", BanglaiId)};
                //context.Database.SqlQuery<ChuXevaBangLai>(cmdText, sqlParams);
                ////return lstChuxe;
            }
        }