public ActionResult Edit(DaiLy model, FormCollection collection)
 {
     try
     {
         // TODO: Add update logic here
         if (ModelState.IsValid)
         {
             if (DaiLyManager.edit(model))
             {
                 putSuccessMessage("Cập nhật thành công");
                 return(RedirectToAction("Details", new { id = model.MaSoDaiLy }));
             }
             else
             {
                 putErrorMessage("Cập nhật thất bại");
             }
         }
         else
         {
             putModelStateFailErrors(ModelState);
         }
         return(View(model));
     }
     catch (Exception ex)
     {
         putErrorMessage(ex.Message);
         return(RedirectToAction("Edit", new { id = model.MaSoDaiLy }));
     }
 }
Пример #2
0
        //Khi Cập nhật thông tin Đại lý
        private void btnCapNhat_Click(object sender, EventArgs e)
        {
            DialogResult dialogResult = MessageBox.Show("Bạn có muốn cập nhật đại lý", "Thông báo", MessageBoxButtons.YesNo);

            if (dialogResult == DialogResult.Yes)
            {
                if (!txbMaSoDaiLy.Text.Equals("") && !txbTenDaiLy.Text.Equals("") && !txbSoDienThoai.Text.Equals("") && !txbSoTaiKhoan.Text.Equals("") && !txbDiaChi.Text.Equals(""))
                {
                    //DaiLy dl = new DaiLy();
                    //dl.MaSoDaiLy = int.Parse(txbMaSoDaiLy.Text);
                    _currentDaiLy.TenDaiLy    = txbTenDaiLy.Text.ToString();
                    _currentDaiLy.DiaChi      = txbDiaChi.Text.ToString();
                    _currentDaiLy.SoDienThoai = txbSoDienThoai.Text.ToString();
                    _currentDaiLy.SoTaiKhoan  = txbSoTaiKhoan.Text.ToString();
                    _currentDaiLy.NganHang    = txbNganHang.Text.ToString();


                    if (DaiLyManager.edit(_currentDaiLy))
                    {
                        MessageBox.Show("Đã sửa đại lý thành công");
                        loadDaiLy();
                    }
                    else
                    {
                        MessageBox.Show("Không sửa được");
                    }
                }
                else
                {
                    MessageBox.Show("Nhập đầy đủ thông tin cần sửa");
                }
            }
            else if (dialogResult == DialogResult.No)
            {
                return;
            }
        }
        public ActionResult UpdateAgency(DaiLy model, FormCollection collection)
        {
            var errors = new List <string>();

            if (ModelState.IsValid)
            {
                var currentUser = Session[Core.Constants.SESSION.USERNAME] as NguoiDung;
                model.MaSoNguoiDung = currentUser.MaSoNguoiDung;
                if (currentUser.DaiLy == null)
                {
                    var result = DaiLyManager.add(model);
                    if (result != 0)
                    {
                        model.MaSoDaiLy       = result;
                        currentUser.DaiLy     = model;
                        currentUser.MaSoDaiLy = result;
                        Session[Core.Constants.SESSION.USERNAME]  = currentUser;
                        TempData[Core.Constants.TEMPDATA.SUCCESS] = new List <string> {
                            "Đăng ký đại lý thành công"
                        };
                    }
                    else
                    {
                        errors.Add("Đăng ký không thành công");
                        TempData[Core.Constants.TEMPDATA.ERRORS] = errors;
                    }
                }
                else
                {
                    if (DaiLyManager.edit(model))
                    {
                        currentUser.DaiLy = model;
                        Session[Core.Constants.SESSION.USERNAME]  = currentUser;
                        TempData[Core.Constants.TEMPDATA.SUCCESS] = new List <string> {
                            "Cập nhật thành công"
                        };
                    }
                    else
                    {
                        errors.Add("Cập nhật không thành công");
                        TempData[Core.Constants.TEMPDATA.ERRORS] = errors;
                    }
                }
                if (errors.Count > 0)
                {
                    TempData[Core.Constants.TEMPDATA.ERRORS] = errors;
                }
                return(RedirectToAction("Agency"));
            }
            else
            {
                foreach (var value in ModelState.Values)
                {
                    if (value.Errors.Count > 0)
                    {
                        foreach (var error in value.Errors)
                        {
                            errors.Add(error.ErrorMessage);
                        }
                    }
                }
                TempData[Core.Constants.TEMPDATA.ERRORS] = errors;
                return(RedirectToAction("Agency"));
            }
        }
Пример #4
0
 public bool delete()
 {
     this.TrangThai = 0;
     return(DaiLyManager.edit(this));
 }