public ActionResult Create(QuickSubmit quickSubmit)
 {
     try
     {
         ModelState.Remove("User.c_Password");
         ModelState.Remove("User.c_ConfirmPassword");
         ModelState.Remove("Url.c_UrlDesc");
         if (ModelState.IsValid)
         {
             _objBl.InsertQuickSubmit(quickSubmit);
             TempData["Msg"] = "Created Successfully!";
             return RedirectToAction("Index");
         }
         else
         {
             ViewBag.CategoryId = new SelectList(_objBl.categoryBl.GetAll().ToList(), "i_CategoryId", "c_CategoryName");
             return View("Index");
         }
     }
     catch (Exception e1)
     {
         TempData["Msg"] = "Insertion Fail: " + e1.Message + " Error relate to: " + e1.Source;
         return RedirectToAction("Index");
     }
 }
Esempio n. 2
0
        public void InsertQuickSubmit(QuickSubmit quickSubmit)
        {
            using (TransactionScope transactionScope = new TransactionScope())
            {
                try
                {
                    tbl_User user = quickSubmit.User;
                    user.c_Password = user.c_ConfirmPassword = new Random().Next(0, 100000).ToString("D6");
                    user.c_Role = User.RoleAuthorizedUser.Value;
                    userBl.Insert(user);

                    tbl_Url url = quickSubmit.Url;
                    url.i_UserId = user.i_UserId; // since inserted above it willl have an id generated for us by EF
                    url.c_UrlDesc = url.c_UrlTitle;
                    url.c_IsApproved = Url.StatusPending.Value;
                    urlBl.Insert(url);

                    // if does not rezch line below iot will rollback any ops/trans
                    transactionScope.Complete();
                }
                catch (Exception e)
                {
                    throw new Exception(e.Message);
                }
            }
        }