示例#1
0
        public IActionResult UpdateCoBan(NhaXe nhaXe)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    throw new Exception("Thông tin không hợp lệ");
                }
                nhaXe = getAssociatedNhaXe(uManager).Result;
                ViewData["TenNhaXe"] = nhaXe.TenNhaXe;
                NhaXe _nhaXe = _context.NhaXe.Find(nhaXe.MaNhaXe);
                if (_nhaXe == null)
                {
                    throw new Exception("Không tìm thấy nhà xe");
                }
                _nhaXe.TenNhaXe     = nhaXe.TenNhaXe;
                _nhaXe.SoLuongXe    = nhaXe.SoLuongXe;
                _nhaXe.Sdt          = nhaXe.Sdt;
                _nhaXe.MauBieuTuong = nhaXe.MauBieuTuong;
                _nhaXe.DiaChi       = nhaXe.DiaChi;

                _context.NhaXe.Update(_nhaXe);
                _context.SaveChanges();
            }
            catch (Exception err) { ModelState.AddModelError("", err.Message); }
            return(View("CoBan", nhaXe));
        }
示例#2
0
        public IActionResult UpdateCoBan(NhaXe nhaxe)
        {
            //flag = 0: create
            //flag = 1: update
            //flag = 2: delete
            if (!ModelState.IsValid)
            {
                return(View(nhaXe));
            }
            NhaXe _nhaXe = null;

            try
            {
                _nhaXe = _context.NhaXe.Find(nhaxe.MaNhaXe);
                if (_nhaXe == null)
                {
                    throw new Exception("Không tìm thấy nhà xe");
                }
                _nhaXe = nhaXe;
                _context.NhaXe.Update(_nhaXe);
                _context.SaveChanges();
            }
            catch (Exception err)
            {
                ModelState.AddModelError("", err.Message);
            }
            return(View(_nhaXe));
        }
示例#3
0
        public async Task <IActionResult> UpdateTtbenxe(TTBenXe tt)
        {
            List <string> message = new List <string>();

            try
            {
                if (!ModelState.IsValid)
                {
                    throw new Exception("Thông tin không hợp lệ");
                }
                TTBenXe _tt = await _context.TTBenXe.FindAsync(tt.Stt);

                if (_tt == null)
                {
                    throw new Exception("không tìm thấy  bảng ghi trạng thái bến xe");
                }
                _tt.Stt = tt.Stt;
                _context.TTBenXe.Update(_tt);
                _context.SaveChanges();
                message.Add("redirect");
                message.Add(Url.Action("TtBenXe"));
            }
            catch (Exception ex)
            {
                message.Add(ex.Message);
                foreach (var value in ModelState.Values)
                {
                    if (value.ValidationState == ModelValidationState.Invalid)
                    {
                        foreach (var modelErr in value.Errors)
                        {
                            message.Add(modelErr.ErrorMessage);
                        }
                    }
                }
            }
            return(Json(message.ToArray()));
        }
        public async Task <IActionResult> CreateLsGiaoDich(GiaoDich giaoDich)
        {
            List <string> messages = new List <string>();

            try
            {
                if (!ModelState.IsValid)
                {
                    throw new Exception("Thông tin không hợp lệ");
                }
                await _context.GiaoDich.AddAsync(giaoDich);

                _context.SaveChanges();
                messages.Add("redirect");
                messages.Add(Url.Action("LsGiaoDich"));
            }
            catch (Exception err)
            {
                messages.Add(err.Message);
                foreach (var value in ModelState.Values)
                {
                    if (value.ValidationState == ModelValidationState.Invalid)
                    {
                        foreach (var modelErr in value.Errors)
                        {
                            messages.Add(modelErr.ErrorMessage);
                        }
                    }
                }
            }
            return(Json(messages.ToArray()));
        }