Ejemplo n.º 1
0
        public void Pending(string orderId)
        {
            if (GetAssignment(orderId) != null)
            {
                return;
            }

            var paymentManager = DomainHub.GetDomain <IPaymentManager>();

            var assignment = new Assignment
            {
                Id     = orderId,
                Time   = DateTime.Now,
                Status = AssignmentStatus.Pending
            };

            assignment.PartitionKey = assignment.Status;
            assignment.RowKey       = assignment.Id;

            AssignmentTable.Insert(assignment);

            assignment.PartitionKey = assignment.RowKey;
            assignment.RowKey       = AssignmentStatus.Tracked;
            AssignmentTable.Insert(assignment);
        }
        public IActionResult Index()
        {
            var configurationManager = DomainHub.GetDomain <IConfigurationManager>();

            ViewBag.Configurations = configurationManager.GetAll();

            return(View());
        }
Ejemplo n.º 3
0
        public async Task <IdentityResult> CreateAsync(ApplicationUser user, CancellationToken cancellationToken)
        {
            var userManager = DomainHub.GetDomain <IUserManager>();

            userManager.Create(user.Id, user.PasswordHash, user.UserName, user.Role);

            return(IdentityResult.Success);
        }
Ejemplo n.º 4
0
        public Session CreateStripePaySession(string orderId, string cancelledUrl, string succeededUrl)
        {
            var applicationManager = DomainHub.GetDomain <IApplicationManager>();
            var application        = applicationManager[orderId];
            var unpaidAmount       = this.GetUnpaidAmount(orderId);

            var currency = "eur";
            var amount   = (long)(100 * unpaidAmount);
            var options  = new SessionCreateOptions
            {
                PaymentMethodTypes = new List <string>
                {
                    "card"
                },
                LineItems = new List <SessionLineItemOptions>
                {
                    new SessionLineItemOptions
                    {
                        PriceData = new SessionLineItemPriceDataOptions
                        {
                            UnitAmount  = amount,
                            Currency    = currency,
                            ProductData = new SessionLineItemPriceDataProductDataOptions
                            {
                                Name = "GNIB/IRP Appointment Service",
                            },
                        },
                        Quantity = 1,
                    },
                },
                Mode       = "payment",
                SuccessUrl = succeededUrl,
                CancelUrl  = cancelledUrl,
            };
            var     service = new SessionService();
            Session session = service.Create(options);

            var payment = new DataAccess.Model.Storage.Payment
            {
                PartitionKey = orderId,
                ChargeId     = session.PaymentIntentId,
                RowKey       = session.PaymentIntentId,
                Time         = DateTime.Now,
                Type         = Stripe,
                Currency     = currency,
                Amount       = ((double)session.AmountTotal) / 100,
                Payer        = application.Email,
                Status       = session.PaymentStatus
            };

            PaymentTable.Insert(payment);

            return(session);
        }
        public bool StripePay(string orderId, string stripeToken, string email)
        {
            var applicationManager = DomainHub.GetDomain <IApplicationManager>();

            var order = applicationManager.GetOrder(orderId);

            var options = new StripeChargeCreateOptions
            {
                Amount   = (int)(order.Amount * 100),
                Currency = EUR,
                SourceTokenOrExistingSourceId = stripeToken
            };

            var service = new StripeChargeService();
            var charge  = service.Create(options);

            if (charge.Paid)
            {
                var payment = new DataAccess.Model.Storage.Payment
                {
                    PartitionKey = orderId,
                    ChargeId     = charge.Id,
                    RowKey       = charge.Id,
                    Time         = DateTime.Now,
                    Type         = Stripe,
                    Currency     = charge.Currency,
                    Amount       = ((double)charge.Amount) / 100,
                    Payer        = charge.Customer?.Email ?? email
                };

                PaymentTable.Insert(payment);
            }

            return(charge.Paid);
        }
Ejemplo n.º 6
0
        public bool VerifyToken(string token)
        {
            var configurationManager = DomainHub.GetDomain <IConfigurationManager>();
            var setToken             = configurationManager[API, Token];

            return(token == setToken);
        }
        public IViewComponentResult Invoke()
        {
            var appointmentManager = DomainHub.GetDomain <IAppointmentManager>();
            var lastAppointments   = appointmentManager.GetLastAppointments();
            var models             = lastAppointments.Select(appointment => new AppointmentModel(appointment));

            return(View(models));
        }
        public IActionResult Index()
        {
            var userManager = DomainHub.GetDomain <IUserManager>();

            ViewBag.Users = userManager.GetAllUsers();

            return(View());
        }
Ejemplo n.º 9
0
        public IActionResult Index()
        {
            var appointmentLetterManager = DomainHub.GetDomain <IAppointmentLetterManager>();
            var appointmentLetters       = appointmentLetterManager.UnassignedLetters;

            ViewBag.AppointmentLetters = appointmentLetters;

            return(View());
        }
        public IViewComponentResult Invoke(bool?isNew = null)
        {
            var applicationManager = DomainHub.GetDomain <IApplicationManager>();

            ViewBag.Assignments = applicationManager.CachedAssignments.ContainsKey(AssignmentStatus.Accepted)
                ? applicationManager.CachedAssignments[AssignmentStatus.Accepted]
                : applicationManager.GetAssignments(AssignmentStatus.Accepted);

            return(View());
        }
Ejemplo n.º 11
0
        public void ApplyRule(RewriteContext context)
        {
            var path = context.HttpContext.Request.Path;

            if (path.Value.StartsWith(ApplicationSettings["UploadedFileRewritingURL"]))
            {
                var fileName   = Path.GetFileName(path.Value);
                var fileStream = DomainHub.GetDomain <IInformationManager>().LoadFile(fileName);
                var response   = context.HttpContext.Response;
                fileStream.CopyTo(response.Body);
            }
        }
Ejemplo n.º 12
0
        public static InformationModel GetInformationModel(IDomainHub domainHub, string key, string language)
        {
            var informationManager = domainHub.GetDomain <IInformationManager>();
            var information        = informationManager[key, language];

            if (information == null)
            {
                return(null);
            }

            return(new InformationModel(information));
        }
Ejemplo n.º 13
0
        public void Pending(string orderId)
        {
            var currentAssignment = GetAssignment(orderId);

            if (currentAssignment != null)
            {
                if (currentAssignment.Status == AssignmentStatus.Accepted)
                {
                    this.UpdataAssignmentStatus(orderId, currentAssignment.Status, AssignmentStatus.Pending);
                }
                return;
            }

            var paymentManager = DomainHub.GetDomain <IPaymentManager>();

            var assignment = new Assignment
            {
                Id     = orderId,
                Time   = DateTime.Now,
                Status = AssignmentStatus.Pending
            };

            assignment.PartitionKey = assignment.Status;
            assignment.RowKey       = assignment.Id;

            AssignmentTable.Insert(assignment);

            assignment.PartitionKey = assignment.RowKey;
            assignment.RowKey       = AssignmentStatus.Tracked;
            AssignmentTable.Insert(assignment);

            var emailApplication = DomainHub.GetDomain <IEmailApplication>();

            emailApplication.NotifyApplicationChangedAsync(orderId, null, assignment.Status).Wait();
        }
Ejemplo n.º 14
0
        public IActionResult Upload(IFormFile upload)
        {
            var informationManager = DomainHub.GetDomain <IInformationManager>();
            var url = informationManager.UploadFile(upload.FileName, upload.ContentType, upload.OpenReadStream());

            return(Ok(new
            {
                fileName = Path.GetFileNameWithoutExtension(url),
                uploaded = true,
                url = url
            }));
        }
Ejemplo n.º 15
0
        public ActionResult Appointment(string date = "yesterday")
        {
            if (date.ToLower() == "yesterday")
            {
                date = DateTime.Now.AddDays(-1).ToString("yyyyMMdd");
            }

            var assignmentManager = DomainHub.GetDomain <IAppointmentManager>();
            var statisticsDate    = date == null
                ? DateTime.Now.Date
                : DateTime.ParseExact(date, "yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture);

            var Statistics = assignmentManager.GetStatistics(statisticsDate, statisticsDate);

            ViewBag.Date = statisticsDate;

            return(View(Statistics.Select(statistics => new AppointmentStatisticsModel(statistics))));
        }
Ejemplo n.º 16
0
        public void Assign(string id, string applicationId)
        {
            var appointmentLetter = AppointmentLetterTable[Unassigned, id];

            var applicationManager = DomainHub.GetDomain <IApplicationManager>();

            applicationManager.Complete(applicationId,
                                        appointmentLetter.AppointmentNo,
                                        appointmentLetter.Time,
                                        appointmentLetter.Name,
                                        appointmentLetter.Category,
                                        appointmentLetter.SubCategory);

            AppointmentLetterTable.Delete(appointmentLetter);

            EnsureCacheLoaded();
            var cached = Cache.FirstOrDefault(letter => letter.EmailId == id);

            if (cached != null)
            {
                Cache.Remove(cached);
            }
        }
Ejemplo n.º 17
0
        public IActionResult Index(string status = AssignmentStatus.Pending)
        {
            var applicationManager = DomainHub.GetDomain <IApplicationManager>();
            var assignments        = applicationManager.GetAssignments(status, true);

            if (status == AssignmentStatus.Complete)
            {
                assignments = assignments.OrderBy(assignment => assignment.AppointmentLetter?.Time ?? DateTime.MaxValue).ToList();
            }
            else
            {
                assignments = assignments.OrderBy(assignment => assignment.Time).ToList();
            }

            ViewBag.Assignments = assignments;
            ViewBag.Status      = status;

            var paymentManager = DomainHub.GetDomain <IPaymentManager>();
            var payments       = new Dictionary <string, List <Payment> >();
            var isPaids        = new Dictionary <string, bool>();

            foreach (var assignment in assignments)
            {
                payments.Add(assignment.Id, paymentManager.GetPayments(assignment.Id));
                isPaids.Add(assignment.Id, paymentManager.IsPaid(assignment.Id));
            }
            ViewBag.Payments = payments;
            ViewBag.IsPaids  = isPaids;

            if (status == AssignmentStatus.Appointed)
            {
                var appointmentLetterManger = DomainHub.GetDomain <IAppointmentLetterManager>();
                var letters = appointmentLetterManger
                              .UnassignedLetters
                              .Where(letter => letter.Time > DateTime.Now.AddDays(-7))
                              .GroupBy(letter => letter.Name.Replace("\r", ""))
                              .ToDictionary(group => group.Key);
                var noLetter = new AppointmentLetter[0];
                ViewBag.AppointmentLetters = assignments
                                             .ToDictionary(assignment => assignment.Id,
                                                           assignment =>
                {
                    var application = applicationManager[assignment.Id];
                    var name        = $"{application.GivenName}  {application.SurName}";
                    return(letters.ContainsKey(name) ? letters[name].ToArray() : noLetter);
                });
            }

            return(View());
        }
Ejemplo n.º 18
0
        public async Task <IActionResult> Index(ApplicationModel model, string reCaptchaResponse)
        {
            if (model.IsInitialized)
            {
                if (model.HasGNIB)
                {
                    if (string.IsNullOrEmpty(model.GNIBNo))
                    {
                        ModelState.AddModelError("GNIBNo", "GNIB number is required.");
                    }
                    else if (!new Regex(@"\d+").IsMatch(model.GNIBNo))
                    {
                        ModelState.AddModelError("GNIBNo", "GNIB number should all be digits.");
                    }

                    if (string.IsNullOrEmpty(model.GNIBExDT))
                    {
                        ModelState.AddModelError("GNIBExDT", "GNIB expired date required.");
                    }
                    else if (!IsFormattedDate(model.GNIBExDT))
                    {
                        ModelState.AddModelError("GNIBExDT", "GNIB expired date format wrong, should be DD/MM/YYYY.");
                    }
                }

                if (!string.IsNullOrEmpty(model.DOB))
                {
                    if (!IsFormattedDate(model.DOB))
                    {
                        ModelState.AddModelError("DOB", "Date of Birth is formatting wrong, should be DD/MM/YYYY.");
                    }
                    else
                    {
                        var dob = DateTime.ParseExact(model.DOB, "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture);
                        if (dob >= DateTime.Now)
                        {
                            ModelState.AddModelError(nameof(model.DOB), "Date of Birth should be at least before today.");
                        }
                    }
                }

                if (!model.UsrDeclaration)
                {
                    ModelState.AddModelError("UsrDeclaration", "You need to confirm to continue.");
                }

                if (model.IsFamily && string.IsNullOrEmpty(model.FamAppNo))
                {
                    ModelState.AddModelError("FamAppNo", "Family number is not selected.");
                }

                if (model.HasPassport)
                {
                    if (string.IsNullOrEmpty(model.PPNo))
                    {
                        ModelState.AddModelError("PPNo", "Passport Number required.");
                    }
                }
                else if (string.IsNullOrEmpty(model.PPReason))
                {
                    ModelState.AddModelError("PPReason", "Passport Number or No Passport Reason required.");
                }

                ViewBag.reCaptchaVerified = null;

                if (ModelState.IsValid &&
                    model.AuthorizeDataUsage)
                {
                    var reCaptchaVerified = (HostingEnvironment.IsDevelopment() ||
                                             await reCaptchaHelper.VerifyAsync(reCaptchaResponse, HttpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString()));

                    if (reCaptchaVerified)
                    {
                        var applicationManager = DomainHub.GetDomain <IApplicationManager>();
                        var application        = new Application
                        {
                            Category       = model.Category,
                            SubCategory    = model.SubCategory,
                            ConfirmGNIB    = model.HasGNIB ? "Renewal" : "New",
                            GNIBNo         = model.GNIBNo,
                            GNIBExDT       = model.GNIBExDT,
                            UsrDeclaration = model.UsrDeclaration ? 'Y' : 'N',
                            Salutation     = model.Salutation,
                            GivenName      = model.GivenName,
                            MidName        = model.MidName,
                            SurName        = model.SurName,
                            DOB            = model.DOB,
                            Nationality    = model.Nationality,
                            Email          = model.Email,
                            FamAppYN       = model.IsFamily ? "Yes" : "No",
                            FamAppNo       = model.FamAppNo,
                            PPNoYN         = model.HasPassport ? "Yes" : "No",
                            PPNo           = model.PPNo,
                            PPReason       = model.PPReason,
                            Comment        = model.Comment
                        };

                        var applicationId = applicationManager.CreateApplication(application);

                        return(RedirectToAction("Order",
                                                new
                        {
                            applicationId = applicationId
                        }));
                    }
                    else
                    {
                        ViewBag.reCaptchaVerified = reCaptchaVerified;
                        model.HasGNIB             = true;
                    }
                }
            }
            else
            {
                ModelState.Clear();
            }

            ViewBag.reCaptchaUserCode  = reCaptchaHelper.reCaptchaUserCode;
            ViewBag.HostingEnvironment = HostingEnvironment;

            return(View(model));
        }
Ejemplo n.º 19
0
        public IActionResult AssignmentInStatus(string token, string status)
        {
            switch (status)
            {
            case AssignmentStatus.Pending:
            case AssignmentStatus.Accepted:
            case AssignmentStatus.Appointed:
            case AssignmentStatus.Duplicated:
                var apiManager = DomainHub.GetDomain <IApiManager>();
                if (apiManager.VerifyToken(token))
                {
                    var applicationManager = DomainHub.GetDomain <IApplicationManager>();
                    var assignments        = applicationManager
                                             .GetAssignments(status, true)
                                             .Select(assignment =>
                    {
                        var assignmentModel = new AssignmentModel(assignment);
                        assignmentModel.Order.AnyCategory = true;
                        return(assignmentModel);
                    });

                    return(Json(assignments));
                }
                break;
            }

            return(Accepted());
        }
        public IActionResult Index(string status = AssignmentStatus.Pending)
        {
            var applicationManager = DomainHub.GetDomain <IApplicationManager>();
            var assignments        = applicationManager.GetAssignments(status, true);

            if (status == AssignmentStatus.Complete)
            {
                assignments = assignments.OrderBy(assignment => assignment.AppointmentLetter?.Time ?? DateTime.MaxValue).ToList();
            }
            else
            {
                assignments = assignments.OrderBy(assignment => assignment.Time).ToList();
            }

            ViewBag.Assignments = assignments;
            ViewBag.Status      = status;

            var paymentManager = DomainHub.GetDomain <IPaymentManager>();
            var payments       = new Dictionary <string, Payment>();

            foreach (var assignment in assignments)
            {
                payments.Add(assignment.Id, paymentManager.GetPayment(assignment.Id));
            }
            ViewBag.Payments = payments;

            return(View());
        }
Ejemplo n.º 21
0
        public async Task NotifyApplicationChangedAsync(string applicationId, string previousStatus, string currentStatus)
        {
            var applicationManager = DomainHub.GetDomain <IApplicationManager>();
            var application        = applicationManager[applicationId];

            var configurationManager = DomainHub.GetDomain <IConfigurationManager>();
            var templateKey          = $"Application{previousStatus}{currentStatus}";
            var time = DateTime.Now;

            if (currentStatus == AssignmentStatus.Complete)
            {
                var order          = applicationManager.GetOrder(applicationId);
                var paymentManager = DomainHub.GetDomain <IPaymentManager>();
                if (paymentManager.IsPaid(applicationId))
                {
                    templateKey += "Paid";
                }
                else
                {
                    templateKey += "Unpaid";
                }

                var appointment = applicationManager.GetAppointmentLetter(applicationId);
                time = appointment.Time;
            }
            var templateId = configurationManager["MailjetTemplate", templateKey];

            if (string.IsNullOrEmpty(templateId))
            {
                await this.NotifyApplicationChangedAsync(applicationId, null, currentStatus);

                return;
            }

            if (templateId != null)
            {
                var mailjetUsername = configurationManager["Mailjet", "Username"];
                var mailjetPassword = configurationManager["Mailjet", "Password"];
                var client          = new MailjetClient(mailjetUsername, mailjetPassword);

                var senderEmail = configurationManager["Mailjet", "SenderEmail"];
                var senderName  = configurationManager["Mailjet", "SenderName"];
                var request     = new MailjetRequest()
                {
                    Resource = Send.Resource
                }
                .Property(Send.FromEmail, senderEmail)
                .Property(Send.FromName, senderName)
                .Property(Send.To, $"{application.GivenName} {application.SurName} <{application.Email}>")
                .Property(Send.Bcc, $"Backup <{senderEmail}>")
                .Property(Send.MjTemplateID, templateId)
                .Property(Send.MjTemplateLanguage, "True")
                .Property(Send.Vars, new JObject
                {
                    { "name", application.GivenName },
                    { "id", application.Id },
                    { "time", time.ToString("dddd, dd MMMM") }
                });

                var response = await client.PostAsync(request);
            }
        }
Ejemplo n.º 22
0
        public IActionResult AssignmentAccepted(string token)
        {
            var apiManager = DomainHub.GetDomain <IApiManager>();

            if (apiManager.VerifyToken(token))
            {
                var applicationManager = DomainHub.GetDomain <IApplicationManager>();
                var assignments        = applicationManager
                                         .GetAssignments(AssignmentStatus.Accepted, true)
                                         .Select(assignment =>
                {
                    var assignmentModel = new AssignmentModel(assignment);
                    assignmentModel.Order.AnyCategory = true;
                    return(assignmentModel);
                });

                return(Json(assignments));
            }

            return(Accepted());
        }