public ActionResult Create([Bind(Include = "Id, Debt, Employee, IsActive, Notes")] Warrant warrant) { Db db = new Db(DbServices.ConnectionString); if (ModelState.IsValid) { try { WarrantServices.Insert(CurrentUser.Id, warrant, db); TempData["Success"] = ResourceServices.GetString(Cf.Data.Resources.ResourceBase.Culture, "UI", "InsertConfirmed"); return(RedirectToAction("Index")); } catch (CfException cfex) { TempData["Failure"] = cfex.ErrorDefinition.LocalizedMessage; } catch (Exception ex) { TempData["Failure"] = ex.Message; } } ViewBag.DebtList = new SelectList(DebtServices.List(db), "Id", "ReferenceNumber"); ViewBag.EmployeeList = new SelectList(EmployeeServices.List(db), "Id", "FirstName"); return(View(warrant)); }
public ActionResult CreateWarrant(WarrantVwViewModel model) { WarrantVwViewModel Model = new WarrantVwViewModel(); try { EmployeeVw employee = EmployeeVwServices.Get(model.Instance.DebtEmployeeId); if (employee == null) { TempData["Failure"] = "الرقم الذاتي غير صحيح"; Model.List = WarrantVwServices.GetByDebtId(model.Instance.DebtId, db); return(PartialView("_WarrantsList", Model)); } // check if this employee is not the debt employee Debt d = DebtServices.Get(model.Instance.DebtId, db); if (d != null) { if (d.Employee == model.Instance.DebtEmployeeId) { TempData["Failure"] = "لا يمكن أن يكفل الموظف نفسه"; Model.List = WarrantVwServices.GetByDebtId(model.Instance.DebtId, db); return(PartialView("_WarrantsList", Model)); } } // check if this employee has been added as a garantaur Warrant ewarrant = WarrantServices.GetByDebt_EmployeeFirstOrNull(model.Instance.DebtId, model.Instance.DebtEmployeeId); if (ewarrant != null) { TempData["Failure"] = "هذا الموظف هو كفيل حالياً لهذه المديونية"; } else { Warrant w = new Warrant() { Debt = model.Instance.DebtId, Employee = model.Instance.DebtEmployeeId, IsActive = model.Instance.IsActive, Notes = model.Instance.Notes }; w = WarrantServices.Insert(CurrentUserId, w, db); } Model.List = WarrantVwServices.GetByDebtId(model.Instance.DebtId, db); return(PartialView("_WarrantsList", Model)); } catch (CfException cfex) { TempData["Failure"] = cfex.ErrorDefinition.LocalizedMessage; //return Json(new { status = false, message = cfex.ErrorDefinition.LocalizedMessage }, JsonRequestBehavior.AllowGet); } catch (Exception ex) { TempData["Failure"] = ex.Message; //return Json(new { status = false, message = ex.Message }, JsonRequestBehavior.AllowGet); } Model.List = WarrantVwServices.GetByDebtId(model.Instance.DebtId, db); return(PartialView("_WarrantsList", Model)); }