Exemple #1
0
        public async Task Post_WhenCalledValidation_ReturnsConflictObjectResult()
        {
            // Arrange
            ValidateViewModel validateViewModel = new ValidateViewModel
            {
                CustomBundle = new CustomBundleViewModel
                {
                    Products = new ProductViewModel[]
                    {
                        new ProductViewModel {
                            Name = "Student Account"
                        },
                        new ProductViewModel {
                            Name = "Current Account"
                        },
                        new ProductViewModel {
                            Name = "Debit Card"
                        }
                    }
                },
                Question = new QuestionViewModel
                {
                    Age       = 18,
                    IsStudent = true,
                    Income    = 200
                }
            };

            // Act
            var result = await _controller.PostValidateCustomBundleAsync(validateViewModel);

            // Assert
            Assert.IsType <ConflictObjectResult>(result);
        }
Exemple #2
0
        public async Task <ActionResult> Index(Guid id)
        {
            var results = await mediator.SendAsync(new ValidateImportNotification(id));

            var model = new ValidateViewModel(results);

            return(View(model));
        }
        public async Task<ActionResult> Index(Guid id)
        {
            var results = await mediator.SendAsync(new ValidateImportNotification(id));

            var model = new ValidateViewModel(results);

            return View(model);
        }
        public JsonResult Validate(ValidateViewModel validateViewModel)
        {
            var api      = new PaysonApi(validateViewModel.UserId, validateViewModel.UserKey, ApplicationId, true);
            var response = api.MakeAccountDetailsRequest();

            if (response.Success)
            {
                return(Json(new { success = true, accountEmail = response.AccountDetails.AccountEmail, enabledForInvoice = response.AccountDetails.EnabledForInvoice, enabledForPaymentPlan = response.AccountDetails.EnabledForPaymentPlan }, JsonRequestBehavior.AllowGet));
            }
            return(Json(new { success = false, error = "Wrong credentials" }, JsonRequestBehavior.AllowGet));
        }
        public static ValidateViewModel ToViewModel(this ValidateResult captcha)
        {
            if (captcha == null)
            {
                return(new ValidateViewModel());
            }
            var model = new ValidateViewModel();

            model.Succeed = captcha.Succeed;
            model.Token   = captcha.Token;
            model.Refresh = !captcha.AllowValidate;
            return(model);
        }
        public IActionResult Validate()
        {
            if (_user.IsAuthenticated)
            {
                ViewBag.User = _user.User; ViewBag.Roles = _user.Roles;
            }

            ValidateViewModel model = new ValidateViewModel();

            ViewData["Title"] = "Validate";

            return(View(model));
        }
        public async Task <ActionResult> Validate(ValidateViewModel model)
        {
            var query = new FindIncidents
            {
                ApplicationIds = new [] { model.ApplicationId }
            };
            var result = await _queryBus.QueryAsync(this.ClaimsUser(), query);

            if (result.TotalCount == 0)
            {
                return(View(model));
            }

            return(Redirect("~/#/application/" + model.ApplicationId + "/"));
        }
        public ActionResult Validate(ValidateViewModel viewModel)
        {
            var post = new Post {
                Classes = viewModel.Classes, Content = viewModel.Command
            };

            var errors = compiler.GetCompilationErrors(post)
                         .Where(x => x.Info.Severity > DiagnosticSeverity.Warning)
                         .Select(x => new EditorError
            {
                Location = x.Location.GetLineSpan(true),
                Message  = x.Info.GetMessage()
            });

            return(Json(new { status = "ok", data = errors }));
        }
        public ActionResult RequestAction(int id)
        {
            Request request = this.requestTasks.Get(id);

            if (request != null)
            {
                ViewBag.Request = request;
                ValidateViewModel vm = new ValidateViewModel(request)
                {
                    ForwardRequest = false
                };
                vm.PopulateDropDowns(this.requestTasks.GetRequestEntities(), this.requestTasks.GetRequestTypes(), this.requestTasks.GetRequestStatuses());
                return(View(vm));
            }
            else
            {
                return(new HttpNotFoundResult());
            }
        }
Exemple #10
0
        public async Task <IActionResult> ForgotPassword(ValidateViewModel v)
        {
            if (ModelState.IsValid)
            {
                Customer customer = await _db.Customer.FirstOrDefaultAsync(cu => cu.Email == v.Email);

                if (customer == null)
                {
                    return(View("ForgotPasswordConfirmation"));
                }

                var          callbackUrl  = Url.Action("ChangePassword", "ChangeDate", new { Id = customer.Id_Customer, email = customer.Email }, protocol: HttpContext.Request.Scheme);
                EmailService emailService = new EmailService();
                await emailService.SendEmailAsync(v.Email, "Изменение пароля",
                                                  $"Для сброса пароля пройдите по ссылке: <a href='{callbackUrl}'>link</a>");

                return(View("ForgotPasswordConfirmation"));
            }
            return(View(v));
        }
Exemple #11
0
        public IActionResult Register(ValidateViewModel model)
        {
            List <Person> AllUsers = _context.User.ToList();
            string        level    = "";

            if (AllUsers.Count == 0)
            {
                level = "Admin";
            }
            else
            {
                level = "Normal";
            }
            if (ModelState.IsValid)
            {
                Person newUser = new Person
                {
                    firstName  = model.firstName,
                    lastName   = model.lastName,
                    email      = model.email,
                    user_level = level,
                    created_at = DateTime.Now,
                    updated_at = DateTime.Now
                };
                PasswordHasher <Person> hasher = new PasswordHasher <Person>();
                newUser.password = hasher.HashPassword(newUser, model.password);
                _context.Add(newUser);
                _context.SaveChanges();
                HttpContext.Session.SetInt32("currentUserId", newUser.id);
                return(RedirectToAction("Dash"));
            }
            else
            {
                return(View(model));
            }
        }
Exemple #12
0
 public IActionResult Index(ValidateViewModel model)
 {
     if (ModelState.IsValid)
     {
         Person newUser = new Person
         {
             firstName  = model.firstName,
             lastName   = model.lastName,
             email      = model.email,
             created_at = DateTime.Now,
             updated_at = DateTime.Now
         };
         PasswordHasher <Person> hasher = new PasswordHasher <Person>();
         newUser.password = hasher.HashPassword(newUser, model.password);
         _context.Add(newUser);
         _context.SaveChanges();
         HttpContext.Session.SetInt32("currentUserId", newUser.id);
         return(RedirectToAction("Users"));
     }
     else
     {
         return(View(model));
     }
 }
        public async Task SaveFile(ValidateViewModel model)
        {
            HeaderModel header = new HeaderModel();

            header.IssuerUuid = _user.User;
            header.IssuerName = SQLData.GetProfileById(_user.User).Name;

            if (String.IsNullOrEmpty(model.Validator))
            {
                header.ValidatorUuid = header.IssuerUuid;
                header.ValidatorName = header.IssuerName;
            }
            else
            {
                header.ValidatorName = model.Validator;
            }

            header.Category = Category.File.ToString();
            header.Stored   = model.StoreFile;

            try
            {
                var file       = model.Files[0];
                var attachment = model.Attachment;

                header.Init();
                header.HeaderId = Utils.Convert.ToHexString(header.GetSimpleHashBytes());

                if (file != null && file.Length > 0)
                {
                    byte[] sourceFile;

                    using (MemoryStream stream = new MemoryStream())
                    {
                        await file.CopyToAsync(stream);

                        sourceFile = stream.ToArray();
                    }

                    if (model.StoreFile)
                    {
                        #region stamping

                        byte[] stampedFile;

                        try
                        {
                            stampedFile = await GetPDF(sourceFile, header.HeaderId);
                        }
                        catch (Exception e)
                        {
                            stampedFile = sourceFile;
                        }

                        #endregion

                        #region hash
                        using (System.Security.Cryptography.HashAlgorithm sha256 = System.Security.Cryptography.SHA256.Create())
                        {
                            header.DataHash = Utils.Convert.ToHexString(sha256.ComputeHash(stampedFile));
                        }
                        #endregion

                        #region store
                        using (MemoryStream stream = new MemoryStream(stampedFile))
                        {
                            S3.Init(_configuration["accessKey"], _configuration["secretKey"], _configuration["storageBucket"]);

                            await S3.WriteObject(stream, header.HeaderId, file.ContentType);
                        }
                        #endregion

                        if (model.Attachment != null)
                        {
                            byte[] attachmentFile;

                            using (MemoryStream stream = new MemoryStream())
                            {
                                await attachment.CopyToAsync(stream);

                                attachmentFile = stream.ToArray();
                            }

                            #region init
                            HeaderModel attachmentHeader = new HeaderModel();
                            attachmentHeader.Init();
                            attachmentHeader.HeaderId      = Utils.Convert.ToHexString(attachmentHeader.GetSimpleHashBytes());
                            attachmentHeader.ValidatorName = model.Validator;
                            attachmentHeader.IssuerName    = model.Validator;
                            attachmentHeader.IssuerUuid    = _user.User;
                            attachmentHeader.Category      = Category.Attachment.ToString();
                            attachmentHeader.Stored        = true;
                            #endregion

                            #region hash
                            using (System.Security.Cryptography.HashAlgorithm sha256 = System.Security.Cryptography.SHA256.Create())
                            {
                                attachmentHeader.DataHash = Utils.Convert.ToHexString(sha256.ComputeHash(attachmentFile));
                            }
                            #endregion

                            #region store
                            using (MemoryStream stream = new MemoryStream(attachmentFile))
                            {
                                await S3.WriteObject(stream, attachmentHeader.HeaderId, attachment.ContentType);
                            }
                            #endregion

                            header.Attachment = attachmentHeader.HeaderId;
                            SQLData.InsertHeader(attachmentHeader);
                        }
                    }
                    else
                    {
                        using (System.Security.Cryptography.HashAlgorithm sha256 = System.Security.Cryptography.SHA256.Create())
                        {
                            header.DataHash = Utils.Convert.ToHexString(sha256.ComputeHash(sourceFile));
                        }
                    }

                    header.GlobalHash = Utils.Convert.ToHexString(header.GetFullHashBytes());

                    SQLData.InsertHeader(header);
                }
            }

            catch (Exception e)
            {
            }
        }
Exemple #14
0
 public async Task <IActionResult> PostValidateCustomBundleAsync([FromBody] ValidateViewModel vvm)
 {
     return(await _customBundlesService.PostValidateCustomBundle(vvm.CustomBundle, vvm.Question));
 }
        public ActionResult RequestAction(ValidateViewModel vm)
        {
            if (ModelState.IsValid)
            {
                Request request = this.requestTasks.Get(vm.Id);
                if (request != null)
                {
                    // only forward requests that are in the 'sent for validation' stage of the workflow
                    if ((request.HasBeenSentForValidation && !request.HasBeenForwardedForScreening) || // allows for 'Edited' status
                        request.IsSentForValidation)
                    {
                        // update Request attributes
                        Mapper.Map <RequestViewModel, Request>(vm, request);
                        request.RequestEntity = this.requestTasks.GetRequestEntity(vm.RequestEntityID);
                        request.RequestType   = this.requestTasks.GetRequestType(vm.RequestTypeID);
                        if (!string.IsNullOrEmpty(vm.RespondBy))
                        {
                            request.RespondBy = DateTime.Parse(vm.RespondBy);
                        }
                        else
                        {
                            request.RespondBy = null;
                        }
                        this.requestTasks.SaveOrUpdateRequest(request);

                        if (vm.RejectRequest)
                        {
                            // set rejected status
                            this.requestTasks.SaveRequestHistory(vm.Id, this.requestTasks.GetRequestStatus(RequestStatus.NAME_REJECTED).Id, User.Identity.Name, vm.RejectReason);

                            // send email notification
                            this.emailTasks.SendRequestRejectedEmail(User.Identity.Name, vm.Id, vm.RejectReason);

                            return(RedirectToAction("Index"));
                        }

                        if (vm.ForwardRequest)
                        {
                            // can't forward request that contains any proposed persons
                            if (!request.HasProposedPersons)
                            {
                                // update status
                                this.requestTasks.SaveRequestHistory(vm.Id, this.requestTasks.GetRequestStatus(RequestStatus.NAME_SENT_FOR_SCREENING).Id, User.Identity.Name);

                                // send email notification
                                this.emailTasks.SendRequestForwardedToConditionalityParticipantsEmail(User.Identity.Name, vm.Id);

                                return(RedirectToAction("Index"));
                            }
                            else
                            {
                                ModelState.AddModelError("Request", "Request containing proposed persons cannot be forwarded until all proposed persons have been replaced by profiles existing in the database.");
                                return(RequestAction(vm.Id));
                            }
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("Request", "Request is not in the right status to be validated.");
                        return(RequestAction(vm.Id));
                    }
                }
                else
                {
                    return(new HttpNotFoundResult());
                }
            }
            return(RequestAction(vm.Id));
        }