public List <ApprovalViewModel> GetApprovals(int approverId)
        {
            List <ApprovalViewModel> listOfApprovals = new List <ApprovalViewModel>();
            List <DbParameter>       parameters      = new List <DbParameter>
            {
                new SqlParameter(Constants.Approval.ApproverId, approverId)
            };

            using (
                IDataReader reader = ExecuteReader(Constants.SPROC.GetApprovals, DbCommandType.StoredProcedure,
                                                   parameters))
            {
                while (reader.Read())
                {
                    ApprovalViewModel approval = new ApprovalViewModel
                    {
                        NeedId         = (int)reader[Constants.Need.Id],
                        NeedTitle      = (string)reader[Constants.Need.Title],
                        ActualAmount   = (int)reader[Constants.Need.ActualAmount],
                        UserId         = (int)reader[Constants.Need.User_Id],
                        UserName       = (string)reader[Constants.Individual.Name],
                        ApprovalStatus = ((string)reader[Constants.Need.Approval_Status])
                    };
                    listOfApprovals.Add(approval);
                }
            }
            return(listOfApprovals);
        }
        public ActionResult Edit(int id, FormCollection collection)
        {
            var updatedModel = new ApprovalViewModel
            {
                Id       = id,
                Name     = Request.Form["Name"],
                Archived = Request.Form["Archived"] == "true"
            };

            try
            {
                var json     = new JavaScriptSerializer().Serialize(updatedModel);
                var response = _apiHelper.Put(CompileUrl(apiAction) + $"?id={id}", json);

                TempData["MessageType"] = "Info";
                TempData["Message"]     = $"Approval, {Request.Form["Name"]}, Edited";
                return(RedirectToAction("Index", ViewBag));
            }
            catch
            {
                TempData["MessageType"] = "Danger";
                TempData["Message"]     = $"There was a problem updating this record. Please try again or contact your system administrator.";
                return(View());
            }
        }
        protected async override void OnAppearing()
        {
            base.OnAppearing();

            App.ReadUnread    = "null";
            App.OrderByText   = Constants.LastPostDateText;
            App.SelectedTitle = string.Empty;
            if (Xamarin.Forms.Application.Current.Properties.ContainsKey("USERID"))
            {
                userId = Convert.ToString(Xamarin.Forms.Application.Current.Properties["USERID"]);
            }
            assignListView.RefreshCommand = new Command(() =>
            {
                assignListView.IsRefreshing = false;
            });


            ViewModel           = new ApprovalViewModel();
            this.BindingContext = ViewModel;

            if (NetworkCheck.IsInternet())
            {
                await ViewModel.GetApprovalData();
            }
            else
            {
                await DisplayAlert("Simon", "No network is available.", "OK");
            }
        }
Ejemplo n.º 4
0
        void SwipeToRight(System.Object sender, Xamarin.Forms.SwipedEventArgs e)
        {
            ApprovalViewModel ViewModel = new ApprovalViewModel();

            this.BindingContext = ViewModel;

            ViewModel.FooterNavigation(SessionService.BaseFooterItems[2]);
        }
Ejemplo n.º 5
0
        public ActionResult Approval(Guid id)
        {
            CheckAdminDepartment();
            var model = new ApprovalViewModel {
                Id = id
            };

            return(View(model));
        }
Ejemplo n.º 6
0
 /// <summary>
 /// To approve or reject  request completed by Technician
 /// /// </summary>
 /// <param name="approvalViewModal">approval details </param>
 public void ApproveOrRejectRequest(ApprovalViewModel approvalViewModal)
 {
     if (approvalViewModal.IsApproved)
     {
         UpdateStatus(approvalViewModal, (int)StatusEnum.Approved);
     }
     else
     {
         UpdateStatus(approvalViewModal, (int)StatusEnum.Pending, true);
     }
 }
Ejemplo n.º 7
0
        public static void PurchasePet(ApprovalViewModel approvalViewModel)
        {
            var approval = ApprovalRepository.FindApprovalByEmail(approvalViewModel.CustomerEmail);

            if (approvalViewModel == null)
            {
                throw new PurchasePetException("No approval found");
            }

            approval.PurchasePet();

            //TransactionManager.Commit();
        }
Ejemplo n.º 8
0
        public static void Approve(ApprovalViewModel approvalViewModel)
        {
            var approval = ApprovalRepository.FindApprovalByEmail(approvalViewModel.CustomerEmail);

            if (approval == null)
            {
                return;
            }

            approval.Approve();

            TransactionManager.Commit();
        }
Ejemplo n.º 9
0
        public static void Reject(ApprovalViewModel pendingApproval)
        {
            var approval = ApprovalRepository.FindApprovalByEmail(pendingApproval.CustomerEmail);

            if (approval == null)
            {
                return;
            }

            approval.Reject();

            TransactionManager.Commit();
        }
Ejemplo n.º 10
0
        public ActionResult Approval(string id)
        {
            ApprovalViewModel model = new ApprovalViewModel();
            int approvalId          = 0;

            if (int.TryParse(id, out approvalId))
            {
                model           = ApprovalList(approvalId, 0, 0).FirstOrDefault();
                ViewBag.Request = RequestList(model.TransactionId, "", 0).FirstOrDefault();
            }

            return(View(model));
        }
Ejemplo n.º 11
0
        public void CloseRequestTest()
        {
            var updateStatus = new ApprovalViewModel()
            {
                Comment    = "Request Closed",
                RequestId  = 1,
                IsApproved = true,
                UserId     = 5
            };

            var response = repairRequestController.ApproveorRejectRequest(updateStatus);

            Assert.IsInstanceOfType(response, typeof(OkResult));
        }
Ejemplo n.º 12
0
        public async Task <ActionResult> Reject([Bind(Include = "RequestId,Desc")] ApprovalViewModel requestVM)
        {
            if (ModelState.IsValid)
            {
                var request = await db.Requests.FindAsync(requestVM.RequestId);

                request.IsApproved      = false;
                request.IsRejected      = true;
                db.Entry(request).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Requests"));
            }
            //   ViewBag.RequestTypeId = new SelectList(db.RequestTypes, "RequestTypeId", "Name", request.RequestTypeId);
            return(View(requestVM));
        }
        /// <summary>
        /// Update approval.
        /// </summary>
        /// <param name="model">The approval information value.</param>
        /// <returns></returns>
        public ResultViewModel Edit(ApprovalViewModel model)
        {
            var result = new ResultViewModel();

            using (TransactionScope scope = new TransactionScope())
            {
                var data = _unitOfWork.GetRepository <Approval>().GetCache(x => x.Id == model.Id).FirstOrDefault();
                data.PurchasingOrg  = model.PurchasingOrg;
                data.LastModifyBy   = _token.EmpNo;
                data.LastModifyDate = DateTime.Now;
                _unitOfWork.GetRepository <Approval>().Update(data);
                this.EditItem(data.Id, model.ApprovalList);
                _unitOfWork.Complete(scope);
            }
            this.ReloadCacheApproval();
            return(result);
        }
Ejemplo n.º 14
0
        public ActionResult Approval(ApprovalViewModel approval)
        {
            CheckAdminDepartment();
            if (ModelState.IsValid)
            {
                var eventModel = new Event
                {
                    Id      = approval.Id,
                    State   = approval.State,
                    Reaseon = approval.Reason
                };

                EventService.Approval(eventModel);
                EventService.SaveChanges();
            }
            return(RedirectToAction("Index"));
        }
        /// <summary>
        /// Insert new approval list.
        /// </summary>
        /// <param name="model">The approval information value.</param>
        /// <returns></returns>
        public ResultViewModel Save(ApprovalViewModel model)
        {
            var result = new ResultViewModel();

            using (TransactionScope scope = new TransactionScope())
            {
                var approval = _mapper.Map <ApprovalViewModel, Approval>(model);
                approval.CreateBy   = _token.EmpNo;
                approval.CreateDate = DateTime.Now;
                _unitOfWork.GetRepository <Approval>().Add(approval);
                _unitOfWork.Complete();
                this.SaveItem(approval.Id, _mapper.Map <IEnumerable <ApprovalItemViewModel>, IEnumerable <ApprovalItem> >(model.ApprovalList));
                _unitOfWork.Complete(scope);
            }
            this.ReloadCacheApproval();
            return(result);
        }
Ejemplo n.º 16
0
        public void TestAcceptPendingApproval_CreatesAcceptedApproval()
        {
            // assemble
            var expectedApprovalState = ApprovalState.Approved;
            var customerEmail         = "*****@*****.**";

            Facade.RequestPetPurchase(customerEmail);

            // act
            var firstPendingApproval = Facade.GetPendingApprovals().FirstOrDefault();

            Facade.Approve(firstPendingApproval);

            // assert
            ApprovalViewModel acceptedApproval = Facade.GetApprovals(ApprovalState.Approved).FirstOrDefault();

            acceptedApproval.ApprovalState.ShouldBeEqualTo(expectedApprovalState);
        }
Ejemplo n.º 17
0
        public IActionResult Index()
        {
            var loggedUser = _usuarioService.Get(User);

            var clientsToApprove = _clienteService.GetAllToApproveClients(loggedUser);
            var finalizedClients = _clienteService.GetAllFinalizedClients();
            var approvedClients  = finalizedClients.Where(x => x.CurrentStatus.Description == EStatus.APROVADO);
            var repprovedClients = finalizedClients.Where(x => x.CurrentStatus.Description == EStatus.REPROVADO);

            var viewModel = new ApprovalViewModel()
            {
                ApprovedClients  = approvedClients,
                ClientsToApprove = clientsToApprove,
                RepprovedClients = repprovedClients,
                Roles            = loggedUser.Roles
            };

            return(View(viewModel));
        }
Ejemplo n.º 18
0
        public IActionResult Approval(int loanId)
        {
            // Populate container with necessary info then send to view
            string user        = User.FindFirst(ClaimTypes.NameIdentifier).Value;
            User   currentUser = _libraryDB.Users.First(x => x.UserId == user);

            // There are two key things the view needs to know:
            // 1. who is viewing the page? owner or borrower (figured out above, set below)
            // 2. what is the state of the loan? pending, checked out, or returned? (handled below)

            ApprovalViewModel approvalViewModel = new ApprovalViewModel();

            approvalViewModel.CurrentUser        = currentUser;
            approvalViewModel.Loan               = _libraryDB.Loans.First(x => x.Id == loanId);
            approvalViewModel.BookBorrower       = _libraryDB.Users.First(x => x.Id == approvalViewModel.Loan.BookLoaner);
            approvalViewModel.BookOwner          = _libraryDB.Users.First(x => x.Id == approvalViewModel.Loan.BookOwner);
            approvalViewModel.Book               = _libraryDB.Books.First(x => x.Id == approvalViewModel.Loan.BookId);
            approvalViewModel.BookTitle          = _libraryDAL.GetBookInfo(approvalViewModel.Book.TitleIdApi).title;
            approvalViewModel.BookBorrowerRating = Convert.ToInt32(approvalViewModel.BookBorrower.CumulatvieRating);

            // If a date is empty, that is how we siganal that a loan is PENDING (book owner has yet to approve/decline)
            if (approvalViewModel.Loan.IsDateEmpty() && approvalViewModel.Loan.LoanStatus == true)
            {
                approvalViewModel.CurrentState = CurrentState.Pending;
            }
            // The date is not empty, which is how we signal a due date was created, thus the book must have been checked out
            else if (approvalViewModel.Loan.LoanStatus == true)
            {
                approvalViewModel.CurrentState = CurrentState.CheckedOut;
            }
            else
            {
                approvalViewModel.CurrentState = CurrentState.Returned;
            }

            return(View(approvalViewModel));
        }
Ejemplo n.º 19
0
 public Task RequestApprovalToTake([FromBody] ApprovalViewModel inputModel) =>
 approvalService.RequestApproval(inputModel.Email, UserType.Giver, Guid.Parse(LoggedUserId));
 public void Add(ApprovalViewModel Approval)
 {
     this._dBContext.Add(Approval);
 }
 public IActionResult Edit([FromBody] ApprovalViewModel model)
 {
     return(Ok(_approval.Edit(model)));
 }
 public IActionResult Save([FromBody] ApprovalViewModel model)
 {
     return(Ok(_approval.Save(model)));
 }
 public void Delete(ApprovalViewModel Approval)
 {
     this._dBContext.Attach(Approval);
     this._dBContext.Entry(Approval).State = EntityState.Modified;
 }
Ejemplo n.º 24
0
        public ActionResult ApprovalDetail(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            ApprovalViewModel approvalVM = new ApprovalViewModel();

            // Get the appliction from DB
            var application = contextDb.LeaveApplications
                              .Include(a => a.Attachments)
                              .SingleOrDefault(a => a.id == id);

            if (application == null)
            {
                return(HttpNotFound("The application you request does not exist in our database. Please contact our IT support."));
            }
            else
            {
                approvalVM.LeaveApplication = application;
                approvalVM.TimeRecords      = application.GetTimeRecords();

                // Get related applications in the same periods
                List <LeaveApplication> relatedApplications = (from a in contextDb.LeaveApplications
                                                               where DbFunctions.TruncateTime(a.EndTime) >= application.StartTime.Date &&
                                                               DbFunctions.TruncateTime(a.StartTime) <= application.EndTime.Date &&
                                                               a.status == _status.approved &&
                                                               a.UserID != application.UserID
                                                               select a).ToList();
                // Fetch each leave days in the same period and has been approved
                foreach (var a in relatedApplications)
                {
                    List <TimeRecord> records = (from r in contextDb.TimeRecords
                                                 where DbFunctions.TruncateTime(r.RecordDate) >= application.StartTime.Date &&
                                                 DbFunctions.TruncateTime(r.RecordDate) <= application.EndTime.Date &&
                                                 r.UserID == a.UserID &&
                                                 r.LeaveType != null
                                                 select r).ToList();
                    foreach (var r in records)
                    {
                        string username = contextDb.ADUsers.Find(r.UserID).UserName;
                        approvalVM.TakenLeaves.Add(new Tuple <DateTime, string, double>
                                                   (
                                                       r.RecordDate,
                                                       username,
                                                       r.LeaveTime)
                                                   );
                    }
                }
                approvalVM.LeaveApplication = application;
                if (application.ManagerIDs.Contains(User.Identity.Name))
                {
                    ViewBag.Authorized = true;
                }
                else
                {
                    ViewBag.Authorized = false;
                }

                return(View(approvalVM));
            }
        }
Ejemplo n.º 25
0
 public IHttpActionResult ApproveorRejectRequest(ApprovalViewModel approvalViewModel)
 {
     repairRequestBL.ApproveOrRejectRequest(approvalViewModel);
     return(Ok());
 }
        public async Task <ActionResult <Loan> > PostLoan([FromBody] ApprovalViewModel model)
        {
            var applicationInfo = _context.LoanApplications.Where(x => x.LoanApplicationId == model.ApplicationId).First();

            Loan loan = new Loan();

            loan.LoanType = new LoanType()
            {
                LoanTypeName = applicationInfo.LoanType,
                InterestRate = getInterest(applicationInfo.LoanType),

                NoOfInstallment = applicationInfo.Installments,
                LoanAmount      = applicationInfo.LoanAmount
            };


            loan.User = new User()
            {
                FirstName        = applicationInfo.UserFirstName,
                LastName         = applicationInfo.UserLastName,
                FatherName       = applicationInfo.UserFatherName,
                MotherName       = applicationInfo.UserMotherName,
                PresentAddress   = applicationInfo.UserPresentAddress,
                PermanentAddress = applicationInfo.UserPermanentAddress,
                City             = applicationInfo.UserCity,
                State            = applicationInfo.UserState,
                ZipCode          = applicationInfo.UserZipCode,
                Country          = applicationInfo.UserCountry,
                Nationality      = applicationInfo.UserNationality,
                Occupation       = applicationInfo.UserOccupation,
                DateOfBirth      = applicationInfo.UserDateOfBirth,
                Gender           = applicationInfo.UserGender,
                Religion         = applicationInfo.UserReligion,
                Mobile           = applicationInfo.UserMobile,
                EmailAddress     = applicationInfo.UserEmailAddress,
            };

            loan.User.Verification = new VerificationSource()
            {
                VerificationType = applicationInfo.UserVerificationType,
                VerificationCode = applicationInfo.UserVerificationCode
            };



            loan.Granter = new Granter()
            {
                FirstName        = applicationInfo.GranterFirstName,
                LastName         = applicationInfo.GranterLastName,
                FatherName       = applicationInfo.GranterFatherName,
                MotherName       = applicationInfo.GranterMotherName,
                PresentAddress   = applicationInfo.GranterPresentAddress,
                PermanentAddress = applicationInfo.GranterPermanentAddress,
                City             = applicationInfo.GranterCity,
                State            = applicationInfo.GranterState,
                ZipCode          = applicationInfo.GranterZipCode,
                Country          = applicationInfo.GranterCountry,
                Nationality      = applicationInfo.GranterNationality,
                Occupation       = applicationInfo.GranterOccupation,
                DateOfBirth      = applicationInfo.GranterDateOfBirth,
                Gender           = applicationInfo.GranterGender,
                Religion         = applicationInfo.GranterReligion,
                Relation         = applicationInfo.GranterRelation,
                Mobile           = applicationInfo.GranterMobile,
                EmailAddress     = applicationInfo.GranterEmailAddress,
            };

            loan.Document = new Document()
            {
                FileName = "File"
            };

            loan.Granter.Verification = new VerificationSource()
            {
                VerificationType = applicationInfo.GranterVerificationType,
                VerificationCode = applicationInfo.GranterVerificationCode
            };

            loan.ApprovedBy = model.ApproveBy;
            loan.OperateBy  = model.OperateBy;
            loan.Status     = new Status()
            {
                LoanStatus = model.Status
            };

            Double getInterest(string loanType)
            {
                double interest = 0;

                if (loanType == "Personal Loan")
                {
                    interest = 10;
                }


                else if (loanType == "Home Loan")
                {
                    interest = 15;
                }


                else if (loanType == "Car Loan")
                {
                    interest = 12;
                }
                else
                {
                    interest = 8;
                }
                return(interest);
            }

            if (model.Status != "Pending")
            {
                loan.IssueDate = model.IssueDate;

                List <LoanInstallment> installments = new List <LoanInstallment>();

                for (int i = 0; i < applicationInfo.Installments; i++)
                {
                    installments.Add(new LoanInstallment
                    {
                        EMI          = getEMI(),
                        ScheduleDate = getScheduleList(i),
                        //ActualPayDate = DateTime.Now,
                        Penalty   = 0,
                        PayAmount = 0,
                        //Reason = ""
                    });
                }

                DateTime getScheduleList(int i)
                {
                    DateTime nextMonth = model.IssueDate.AddMonths(i + 1);



                    return(nextMonth);
                }

                Double getEMI()
                {
                    var loanAmount       = applicationInfo.LoanAmount;
                    var interest         = getInterest(applicationInfo.LoanType);
                    var numberOfPayments = applicationInfo.Installments;
                    // rate of interest and number of payments for monthly payments
                    var rateOfInterest = interest / 1200;


                    // loan amount = (interest rate * loan amount) / (1 - (1 + interest rate)^(number of payments * -1))
                    var paymentAmount = (rateOfInterest * loanAmount) / (1 - Math.Pow(1 + rateOfInterest, numberOfPayments * -1));

                    return(paymentAmount);
                }

                loan.LoanInstallments = installments;


                _context.Loans.Add(loan);

                await _context.SaveChangesAsync();

                _context.LoanApplications.Remove(applicationInfo);

                await _context.SaveChangesAsync();
            }



            return(Ok());
        }