コード例 #1
0
        public ActionResult Edit(tbCarrier model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    TempData["Exists"] = true;
                    var msg = string.Join("<br>", ModelState.Where(t => t.Value.Errors.Count > 0).Select(t => t.Value.Errors[0].ErrorMessage));
                    TempData["Message"] = string.Format(msg, model.NickName);
                    return(View(model));
                }


                using (var bll = new CarrierBll())
                {
                    bll.Update(model);
                    bll.Save();
                }
                TempData["Exists"]  = true;
                TempData["Message"] = string.Format("{0} successfully updated!", model.NickName);
                return(RedirectToAction("Index"));
            }
            catch (MyException ex)
            {
                TempData["Exists"]  = true;
                TempData["Message"] = string.Format(ex.Message, model.NickName);
                return(View(model));
            }
            catch (Exception ex)
            {
                TempData["Exists"]  = true;
                TempData["Message"] = string.Format(ex.Message, model.NickName);
                return(View(model));
            }
        }
コード例 #2
0
 public ActionResult Edit(int id)
 {
     using (var bll = new CarrierBll())
     {
         tbCarrier carrier = bll.Find(id);
         return(View(carrier));
     }
 }
コード例 #3
0
 public ActionResult Delete(int id)
 {
     using (var bll = new CarrierBll())
     {
         tbCarrier carrier = bll.Find(id);
         bll.Delete(carrier);
         bll.Save();
         return(RedirectToAction("Index"));
     }
 }