Example #1
0
        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));
        }
Example #2
0
        // GET: Warrant/Delete/5
        public ActionResult Delete(Nullable <int> id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            Db      db      = new Db(DbServices.ConnectionString);
            Warrant warrant = WarrantServices.Get(id.Value, db);

            if (warrant == null)
            {
                return(HttpNotFound());
            }
            return(View(warrant));
        }
Example #3
0
        // GET: Warrant/Edit/5
        public ActionResult Edit(Nullable <int> id)
        {
            Db db = new Db(DbServices.ConnectionString);

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Warrant warrant = WarrantServices.Get(id.Value, db);

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

            ViewBag.DebtList     = new SelectList(DebtServices.List(db), "Id", "ReferenceNumber", warrant.Debt);
            ViewBag.EmployeeList = new SelectList(EmployeeServices.List(db), "Id", "FirstName", warrant.Employee);
            return(View(warrant));
        }
Example #4
0
 public ActionResult DeleteConfirmed(int id)
 {
     try
     {
         Db db = new Db(DbServices.ConnectionString);
         WarrantServices.Delete(CurrentUser.Id, id, db);
         TempData["Success"] = ResourceServices.GetString(Cf.Data.Resources.ResourceBase.Culture, "UI", "DeleteConfirmed");
         // return RedirectToAction("Index");
     }
     catch (CfException cfex)
     {
         TempData["Failure"] = cfex.ErrorDefinition.LocalizedMessage;
     }
     catch (Exception ex)
     {
         TempData["Failure"] = ex.Message;
     }
     // return View(warrant);
     return(RedirectToAction("Index"));
 }
        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));
        }