Esempio n. 1
0
        public async Task UpdateApplicationAsync(VendorApplication application)
        {
            _appDbContext.VendorApplications.Update(application);
            await _appDbContext.SaveChangesAsync();

            //var ApplicationCount = (vendorApplications.Where(p => p.Status == "Pending")).Count();
            //await _hubContext.Clients.All.SendAsync("updatePurchase", OrderCount);
        }
Esempio n. 2
0
        public async Task <VendorApplication> AddAsync(VendorApplication application)
        {
            await _appDbContext.VendorApplications.AddAsync(application);

            await _appDbContext.SaveChangesAsync();

            return(application);
        }
        public async Task <IActionResult> DeclineApplication(ViewApplicationViewModel model)
        {
            VendorApplication application = await _vendorApplicationRepository.GetApplicationByIdAsync(model.VendorApplicationId);

            application.Status        = "Declined";
            application.RejectMessage = model.RejectMessage;

            await _vendorApplicationRepository.UpdateApplicationAsync(application);

            return(RedirectToAction("ListApplications", "VendorApplication"));
        }
        public async Task <IActionResult> ApplicationApproval(ApplicationApprovalViewModel model)
        {
            VendorApplication application = await _vendorApplicationRepository.GetApplicationByIdAsync(model.ApplicationId);

            if (ModelState.IsValid)
            {
                //Add the user to the VendorRole
                ApplicationUser user = await _userManager.FindByIdAsync(application.ApplicantId);


                //Add the user to vendorUser table

                VendorUser vendorUser = new VendorUser
                {
                    FirstName    = user.FirstName,
                    LastName     = user.LastName,
                    UserName     = user.UserName,
                    PhoneNumber  = user.PhoneNumber,
                    IDNumber     = user.IDNumber,
                    PasswordHash = user.PasswordHash,
                    CardNumber   = model.CardNumber,
                    PhotoIDUrl   = application.IdProofUrl
                };

                //remove existing user
                await _userManager.DeleteAsync(user);

                //add new vendorUser
                IdentityResult result = await _vendorUserManager.CreateAsync(vendorUser);

                if (result.Succeeded)
                {
                    var vendor = await _userManager.FindByPhoneNumber(user.PhoneNumber);

                    await _userManager.AddToRoleAsync(vendor, "Vendor");

                    application.Status = "Approved";
                    await _vendorApplicationRepository.UpdateApplicationAsync(application);

                    return(RedirectToAction("ListApplications", "VendorApplication"));
                }
                else
                {
                    foreach (var error in result.Errors)
                    {
                        ModelState.AddModelError("", error.Description);
                    }
                }
            }
            return(View());
        }
        public async Task <IActionResult> EditAsync(int applicationId)
        {
            VendorApplication application = await _vendorApplicationRepository.GetApplicationByIdAsync(applicationId);


            EditApplicationViewModel editApplicationViewModel = new EditApplicationViewModel
            {
                VendorApplicationId       = application.VendorApplicationId,
                ExitingIdProofURL         = application.IdProofUrl,
                ExistingResidencyProofURL = application.ResidencyProofUrl,
                FullName      = application.ApplicantName,
                Status        = application.Status,
                RejectMessage = application.RejectMessage,
                ApplicantId   = application.ApplicantId
            };

            return(View(editApplicationViewModel));
        }
        public async Task <IActionResult> EditAsync(EditApplicationViewModel model)
        {
            if (ModelState.IsValid)
            {
                VendorApplication application = await _vendorApplicationRepository.GetApplicationByIdAsync(model.VendorApplicationId);

                application.ApplicantName   = model.FullName;
                application.ApplicationDate = DateTime.Now;

                //make all application pending after editing
                application.Status        = "Pending";
                application.RejectMessage = null;

                if (model.IdProof != null)
                {
                    if (model.ExitingIdProofURL != null)
                    {
                        string filePath = Path.Combine(_webHostEnvironment.WebRootPath + model.ExitingIdProofURL);
                        System.IO.File.Delete(filePath);
                    }

                    application.IdProofUrl = ProcessUploadedImage(model.IdProof);
                }

                if (model.ResidencyProof != null)
                {
                    if (model.ExistingResidencyProofURL != null)
                    {
                        string filePath = Path.Combine(_webHostEnvironment.WebRootPath + model.ExistingResidencyProofURL);
                        System.IO.File.Delete(filePath);
                    }

                    application.ResidencyProofUrl = ProcessUploadedImage(model.ResidencyProof);
                }

                await _vendorApplicationRepository.UpdateApplicationAsync(application);

                return(RedirectToAction("MyApplications", new { applicantId = application.ApplicantId }));
            }
            return(View());
        }
        public async Task <IActionResult> ViewApplicationAsync(int applicationId)
        {
            VendorApplication application = await _vendorApplicationRepository.GetApplicationByIdAsync(applicationId);

            //Currency currency = await _currencyRepository.GetCurrencyByNameAsync(purchase.PaymentMethods.First().PaymentMethodName);
            //PaymentMethod paymentMethod = purchase.PaymentMethods.First();
            ApplicationUser user = await _userManager.FindByIdAsync(application.ApplicantId);


            var vm = new ViewApplicationViewModel
            {
                VendorApplicationId = application.VendorApplicationId,
                Applicant           = user,
                IdProofUrl          = application.IdProofUrl,
                ResidenceProof      = application.ResidencyProofUrl,
                ApplicationDate     = application.ApplicationDate,
                RejectMessage       = application.RejectMessage
            };

            return(View(vm));
        }
        public async Task <IActionResult> CreateAsync(CreateVendorApplicationViewModel model)
        {
            if (ModelState.IsValid)
            {
                string IdProofPath        = ProcessUploadedImage(model.IdProof);
                string ResidencyProofPath = ProcessUploadedImage(model.ResidencyProof);


                VendorApplication newVendorApplication = new VendorApplication
                {
                    ApplicantName     = model.FullName,
                    IdProofUrl        = IdProofPath,
                    ResidencyProofUrl = ResidencyProofPath,
                    ApplicantId       = model.ApplicantId,
                    ApplicationDate   = DateTime.Today,
                    Status            = "Pending"
                };

                await _vendorApplicationRepository.AddAsync(newVendorApplication);

                return(RedirectToAction("ApplicationComplete"));
            }
            return(View());
        }
        private void LoadCachedApplicationData()
        {
            var appIdCookie = Request.Cookies["VendorApplicationId"];

            if (appIdCookie != null)
            {
                var applicationXmlFile = Path.Combine(Server.MapPath("~/Vendors/Applications"), 
                    String.Format("{0}.xml", appIdCookie.Value));

                if (File.Exists(applicationXmlFile))
                {
                    using (var textReader = new StreamReader(applicationXmlFile))
                    {
                        var xmlSerializer = new XmlSerializer(VendorApplication.GetType());
                        _vendorApplication = (VendorApplication)xmlSerializer.Deserialize(textReader);
                        textReader.Close();
                    }
                }
            }
        }