public ActionResult Create()
        {
            Db db = new Db(DbServices.ConnectionString);

            ViewBag.GuarantorList = new SelectList(GuarantorServices.List(db), "Id", "Notes");
            return(View());
        }
        // GET: Guarantor/Delete/5
        public ActionResult DeleteGuarantorWithStatement(Nullable <int> id, int ProductId)
        {
            //ViewBag.ModuleName = moduleName;
            ViewBag.Title         = delete;
            ViewBag.Delete        = delete;
            ViewBag.Yes           = yes;
            ViewBag.No            = no;
            ViewBag.ConfirmDelete = confirmDelete;
            ViewBag.Action        = delete;

            ViewBag.TitleGuarantor = TitleGuarantor;

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            Db        db        = new Db(DbServices.ConnectionString);
            Guarantor guarantor = GuarantorServices.Get(id.Value, db);

            if (guarantor == null)
            {
                return(HttpNotFound());
            }
            ViewBag.ProductId = ProductId;
            return(PartialView(guarantor));
        }
        public ActionResult Create([Bind(Include = "Guarantor, GrossSalary, DeductionsAmount, NetSalary, ExceptionalIncome")] GuarantorStatement guarantorStatement)
        {
            Db db = new Db(DbServices.ConnectionString);

            if (ModelState.IsValid)
            {
                try
                {
                    GuarantorStatementServices.Insert(CurrentUser.Id, guarantorStatement, 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.GuarantorList = new SelectList(GuarantorServices.List(db), "Id", "Notes");
            return(View(guarantorStatement));
        }
示例#4
0
        public ActionResult Create([Bind(Include = "Id, RefundableProduct, SubNumber, Employee, GuarantorStatus, Notes")] Guarantor guarantor)
        {
            Db db = new Db(DbServices.ConnectionString);

            if (ModelState.IsValid)
            {
                try
                {
                    GuarantorServices.Insert(CurrentUser.Id, guarantor, 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.EmployeeList          = new SelectList(EmployeeServices.List(db), "Id", "FirstName");
            ViewBag.GuarantorStatusList   = new SelectList(GuarantorStatusServices.List(db), "Id", "Name");
            ViewBag.RefundableProductList = new SelectList(RefundableProductServices.List(db), "Product", "Name");
            return(View(guarantor));
        }
        public ActionResult Approve(int?id)
        {
            if (id == null)
            {
                return(RedirectToAction("ManageValidRequests"));
            }
            try
            {
                // 1- update loan reuest status
                Request request = RequestServices.Get(id.Value);
                request.RequestStatus = (int)RequestStatusEnum.Approved;
                RequestServices.Update(request);

                // 2- update guarantors status
                List <Guarantor> Guarantors = GuarantorServices.GetByRefundableProduct(id.Value);
                for (int i = 0; i < Guarantors.Count; i++)
                {
                    Guarantor temp = Guarantors[i];
                    temp.GuarantorStatus = (int)GuarantorStatusEnum.UnderStudy;
                    GuarantorServices.Update(temp);
                }
            }
            catch (Exception ex)
            {
            }
            return(RedirectToAction("ManageValidRequests"));
        }
示例#6
0
        // GET: Guarantor/Delete/5
        public ActionResult Delete(Nullable <int> id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            Db        db        = new Db(DbServices.ConnectionString);
            Guarantor guarantor = GuarantorServices.Get(id.Value, db);

            if (guarantor == null)
            {
                return(HttpNotFound());
            }
            return(View(guarantor));
        }
        public ActionResult EditGuarantorWithStatement(GuarantorWithStatmentViewModel model)
        {
            try
            {
                Db db = new Db(DbServices.ConnectionString);
                if (!(db.Connection.State == ConnectionState.Open))
                {
                    db.Connection.Open();
                }
                db.Transaction = db.Connection.BeginTransaction();

                if (ModelState.IsValid)
                {
                    try
                    {
                        // 1- Update Guaratntor
                        GuarantorServices.Update(CurrentUser.Id, model.Guarantor, db);

                        //2-Update GuarantorStatement
                        model.GuarantorStatement.Guarantor = model.Guarantor.Id;
                        GuarantorStatementServices.Update(CurrentUser.Id, model.GuarantorStatement, db);

                        TempData["Success"] = ResourceServices.GetString(Cf.Data.Resources.ResourceBase.Culture, "UI", "UpdateConfirmed");
                    }
                    catch (CfException cfex)
                    {
                        TempData["Failure"] = cfex.ErrorDefinition.LocalizedMessage;
                    }
                    catch (Exception ex)
                    {
                        TempData["Failure"] = ex.Message;
                    }
                }

                if (db.Transaction != null)
                {
                    db.Transaction.Commit();
                }
                return(RedirectToAction("Details", new { id = model.Guarantor.RefundableProduct }));
            }
            catch
            {
                return(View());
            }
        }
        // GET: GuarantorStatement/Edit/5
        public ActionResult Edit(Nullable <int> guarantor)
        {
            Db db = new Db(DbServices.ConnectionString);

            if (guarantor == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            GuarantorStatement guarantorStatement = GuarantorStatementServices.Get(guarantor.Value, db);

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

            ViewBag.GuarantorList = new SelectList(GuarantorServices.List(db), "Id", "Notes", guarantorStatement.Guarantor);
            return(View(guarantorStatement));
        }
示例#9
0
 public ActionResult DeleteConfirmed(int id)
 {
     try
     {
         Db db = new Db(DbServices.ConnectionString);
         GuarantorServices.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(guarantor);
     return(RedirectToAction("Index"));
 }
示例#10
0
        // GET: Guarantor/Edit/5
        public ActionResult Edit(Nullable <int> id)
        {
            Db db = new Db(DbServices.ConnectionString);

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Guarantor guarantor = GuarantorServices.Get(id.Value, db);

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

            ViewBag.EmployeeList          = new SelectList(EmployeeServices.List(db), "Id", "FirstName", guarantor.Employee);
            ViewBag.GuarantorStatusList   = new SelectList(GuarantorStatusServices.List(db), "Id", "Name", guarantor.GuarantorStatus);
            ViewBag.RefundableProductList = new SelectList(RefundableProductServices.List(db), "Product", "Name", guarantor.RefundableProduct);
            return(View(guarantor));
        }
        public string RejectGuarantor(int?id)
        {
            string StartDivReject = "<div class='alert alert-danger no-border mb-2' role='alert'><strong>";
            string EndDiv         = "</strong></div> ";

            try
            {
                if (id == null)
                {
                    return("Error");
                }
                Guarantor g = GuarantorServices.Get(id.Value);
                g.GuarantorStatus = (int)GuarantorStatusEnum.Rejected;
                GuarantorServices.Update(g);
            }
            catch (Exception ex)
            {
                return("Error");
            }
            return(StartDivReject + "Rejected" + EndDiv);
        }
        public ActionResult EditGuarantorWithStatement(int?id)
        {
            ViewBag.ModuleName = moduleName;
            ViewBag.Action     = update;
            ViewBag.Update     = update;
            ViewBag.Save       = save;
            ViewBag.Back       = back;
            Db db = new Db(DbServices.ConnectionString);

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Guarantor guarantor = GuarantorServices.Get(id.Value, db);

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


            GuarantorStatement guarantorStatement = GuarantorStatementServices.Get(guarantor.Id, db);

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


            ViewBag.EmployeeList        = new SelectList(EmployeeServices.List(db), "Id", "Id_Name", guarantor.Employee);
            ViewBag.GuarantorStatusList = new SelectList(GuarantorStatusServices.List(db), "Id", "Name", guarantor.GuarantorStatus);
            ViewBag.ProductId           = guarantor.RefundableProduct;
            GuarantorWithStatmentViewModel vm = new GuarantorWithStatmentViewModel();

            vm.Guarantor          = guarantor;
            vm.GuarantorStatement = guarantorStatement;


            return(PartialView(vm));
        }
        public ActionResult CreateGuarantorWithStatement(GuarantorWithStatmentViewModel model)
        {
            try
            {
                Db db = new Db(DbServices.ConnectionString);
                if (!(db.Connection.State == ConnectionState.Open))
                {
                    db.Connection.Open();
                }
                db.Transaction = db.Connection.BeginTransaction();

                if (ModelState.IsValid)
                {
                    try
                    {
                        model.Guarantor.GuarantorStatus = (int)GuarantorStatusEnum.New;
                        // 1- Add Guaratntor
                        Guarantor g = GuarantorServices.Insert(CurrentUser.Id, model.Guarantor, db);

                        //2-Add GuarantorStatement
                        model.GuarantorStatement.Guarantor = g.Id;
                        GuarantorStatement gs = GuarantorStatementServices.Insert(CurrentUser.Id, model.GuarantorStatement, db);

                        Request           r  = db.RequestGet(model.Guarantor.RefundableProduct);
                        RefundableProduct rp = db.RefundableProductGet(model.Guarantor.RefundableProduct);

                        //Calculate Solvency
                        GetEmployeeSolvencyFilter filter = new GetEmployeeSolvencyFilter()
                        {
                            EmployeeId  = model.Guarantor.Employee,
                            Amount      = r.Amount,
                            Date        = r.Date,
                            Installment = rp.Installment,
                            GrossSalary = model.GuarantorStatement.GrossSalary,
                            NetSalary   = model.GuarantorStatement.NetSalary
                        };
                        GetEmployeeSolvencyResult solvencyResult = db.GetEmployeeSolvencyFirstOrDefault(filter);

                        // update notes field at Guarantor
                        string result = getResult(solvencyResult);
                        g.Notes = result;
                        GuarantorServices.Update(CurrentUser.Id, g, db);

                        TempData["Success"] = ResourceServices.GetString(Cf.Data.Resources.ResourceBase.Culture, "UI", "InsertConfirmed");
                    }
                    catch (CfException cfex)
                    {
                        TempData["Failure"] = cfex.ErrorDefinition.LocalizedMessage;
                    }
                    catch (Exception ex)
                    {
                        TempData["Failure"] = ex.Message;
                    }
                }

                if (db.Transaction != null)
                {
                    db.Transaction.Commit();
                }
                return(RedirectToAction("Details", new { id = model.Guarantor.RefundableProduct }));
            }
            catch
            {
                return(View("Details"));
            }
        }