示例#1
0
 public ActionResult Delete(int id)
 {
     using (var bll = new RateBll())
     {
         tbRate rate = bll.Find(id);
         bll.Delete(rate);
         bll.Save();
         return(RedirectToAction("Index"));
     }
 }
示例#2
0
 public ActionResult Edit(tbRate model)
 {
     try
     {
         if (!ModelState.IsValid)
         {
             using (var bll = new CarrierBll())
             {
                 TempData["carriers"] = bll.Find().OrderBy(t => t.NickName).Select(t => new SelectListItem {
                     Text = t.NickName, Value = t.Id.ToString()
                 }).ToList();
                 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"] = msg;
                 return(View(model));
             }
         }
         model.IdUser = LoggedUserModel.idUser ?? 0;
         using (var bll = new RateBll())
         {
             model.Rate = Convert.ToDecimal(model.Rate);
             bll.Update(model);
             bll.Save();
         }
         TempData["Exists"]  = true;
         TempData["Message"] = "Rate successfully registered!";
         return(RedirectToAction("Index"));
     }
     catch (MyException ex)
     {
         using (var bll = new CarrierBll())
         {
             TempData["carriers"] = bll.Find().OrderBy(t => t.NickName).Select(t => new SelectListItem {
                 Text = t.NickName, Value = t.Id.ToString()
             }).ToList();
             TempData["Exists"]  = true;
             TempData["Message"] = ex.Message;
             return(View(model));
         }
     }
     catch (Exception ex)
     {
         using (var bll = new CarrierBll())
         {
             TempData["carriers"] = bll.Find().OrderBy(t => t.NickName).Select(t => new SelectListItem {
                 Text = t.NickName, Value = t.Id.ToString()
             }).ToList();
             TempData["Exists"]  = true;
             TempData["Message"] = ex.Message;
             return(View(model));
         }
     }
 }