Esempio n. 1
0
        // GET: Debt/Delete/5
        public ActionResult Delete(Nullable <int> id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            Db   db   = new Db(DbServices.ConnectionString);
            Debt debt = DebtServices.Get(id.Value, db);

            if (debt == null)
            {
                return(HttpNotFound());
            }
            return(View(debt));
        }
Esempio n. 2
0
        // GET: Debt/Edit/5
        public ActionResult Edit(Nullable <int> id)
        {
            Db db = new Db(DbServices.ConnectionString);

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Debt debt = DebtServices.Get(id.Value, db);

            if (debt == null)
            {
                return(HttpNotFound());
            }

            ViewBag.IssuerList   = new SelectList(IssuerServices.List(db), "Id", "Name", debt.Issuer);
            ViewBag.EmployeeList = new SelectList(EmployeeServices.List(db), "Id", "FirstName", debt.Employee);
            return(View(debt));
        }
        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));
        }