public async Task FormResponseRepository_RespondForm_Success() { //arrange IFormBuildRepository buildRepository = new FormBuildRepository(_dbContext); FormBuild formBuild = new FormBuild("Teste", DateTime.Now); IntFieldBuilder intField = new IntFieldBuilder("value_test", 5, 10, true); formBuild.AddField(intField); await buildRepository.AddAsync(formBuild); await _unitOfWork.SaveChangesAsync(); FormResponse formResponse = new FormResponse(formBuild); IntFieldResponse intFieldResponse = new IntFieldResponse(intField); intFieldResponse.SetValue(10); formResponse.AddField(intFieldResponse); //act await _repository.AddAsync(formResponse); await _unitOfWork.SaveChangesAsync(); //assert Assert.True(intFieldResponse.Id > 0); }
public JsonResult HandlePartyWallImageForm(PartyWallImageForm partyWallImageForm) { FormResponse formResponse = new FormResponse(); // TODO: safety check that current member is associated with this party if (this.ModelState.IsValid && partyWallImageForm.PartyWallImage.ContentLength > 0 && partyWallImageForm.PartyWallImage.InputStream.IsImage()) { // if previous id was set, then delete that media from the cms as it would become an orphan - there are likely to be ophans anyway, as user could upload and then disappear from that page if (partyWallImageForm.LastPartyWallImageId.HasValue) { IMedia media = this.Services.MediaService.GetById(partyWallImageForm.LastPartyWallImageId.Value); this.Services.MediaService.Delete(media); } int id = PartyWallImages.CreatePartyWallImage(partyWallImageForm.PartyWallImage); formResponse.Message = JsonConvert.SerializeObject(this.Umbraco.TypedMedia(id)); //TODO:S3URL //formResponse.Message = JsonConvert.SerializeObject(new { id = id, url = this.Umbraco.TypedMedia(id).GetProperty("umbracoFile").Value.ToString() }); //TODO:S3URL formResponse.Success = true; } else { formResponse.Errors = this.ModelState.GetErrors(); } return(Json(formResponse, "text/plain")); }
public async Task FormResponseRepository_RespondFormMultiplesFields_Success() { //arrange FormBuild formBuild = new FormBuild("Test", DateTime.Now); IntFieldBuilder intField = new IntFieldBuilder("age", 5, 10, true); TextFieldBuilder textField = new TextFieldBuilder("name"); formBuild.AddField(intField); formBuild.AddField(textField); FormResponse formResponse = new FormResponse(formBuild); IntFieldResponse intFieldResponse = new IntFieldResponse(intField); intFieldResponse.SetValue(10); formResponse.AddField(intFieldResponse); TextFieldResponse textFieldResponse = new TextFieldResponse(textField); textFieldResponse.SetValue("Maria"); formResponse.AddField(textFieldResponse); //act await _repository.AddAsync(formResponse); await _unitOfWork.SaveChangesAsync(); //assert Assert.True(intFieldResponse.Id > 0); }
public async Task FormResponseRepository_DeleteFormResponse_Success() { //arrange FormBuild formBuild = new FormBuild("Teste", DateTime.Now); IntFieldBuilder intField = new IntFieldBuilder("value_test", 5, 10, true); formBuild.AddField(intField); FormResponse formResponse = new FormResponse(formBuild); IntFieldResponse intFieldResponse = new IntFieldResponse(intField); intFieldResponse.SetValue(10); formResponse.AddField(intFieldResponse); await _repository.AddAsync(formResponse); await _unitOfWork.SaveChangesAsync(); int formResponseId = formResponse.Id; //act await _repository.RemoveAsync(formResponseId); await _unitOfWork.SaveChangesAsync(); FormResponse formResponseNotFound = await _dbContext.FormResponses.FindAsync(formResponseId); //assert Assert.Null(formResponseNotFound); }
public void FormResponseService_UpdateFormResponseValid_ResultValid() { //arrange FormBuild formBuild = new FormBuild("Teste", DateTime.Now); IntFieldBuilder intField = new IntFieldBuilder("value_test", 5, 10, true); TextFieldBuilder textField = new TextFieldBuilder("text"); formBuild.AddField(textField); formBuild.AddField(intField); FormResponse formResponse = new FormResponse(formBuild); IntFieldResponse intResponse = new IntFieldResponse(intField); intResponse.SetValue(10); TextFieldResponse textResponse = new TextFieldResponse(textField); textResponse.SetValue("valid"); formResponse.AddField(intResponse); formResponse.AddField(textResponse); _repository.Update(formResponse); //act ValidationResult result = _service.Update(formResponse); //assert Assert.True(result.IsValid, "Formulário não está válido"); }
public ActionResult HandleProfileBillingAddressForm(ProfileBillingAddressForm profileBillingAddressForm) { FormResponse formResponse = new FormResponse(); if (this.ModelState.IsValid) { Address address = new Address( profileBillingAddressForm.Address1, profileBillingAddressForm.Address2, profileBillingAddressForm.TownCity, profileBillingAddressForm.Postcode); IPartier partier = this.Members.GetCurrentPartier(); partier.BillingAddress = address; this.CheckRegistrationComplete(partier); formResponse.Success = true; } else { formResponse.Errors = this.ModelState.GetErrors(); } return(Json(formResponse, "text/plain")); }
public FormResponse DeletePartyWallItem([FromUri] int messageId) { FormResponse formResponse = new FormResponse(); PartyHost partyHost = (PartyHost)this.Members.GetCurrentMember(); // is party host the host of the party associated with message being deleted ? MessageRow messageRow = this.DatabaseContext.Database.SingleOrDefault <MessageRow>(@" SELECT A.MessageId, A.MemberId, A.Text, A.Image, A.Timestamp FROM wonderlandMessage A LEFT OUTER JOIN wonderlandMemberParty B ON A.MemberID = B.MemberId WHERE A.MessageId=@0 AND B.PartyGuid=@1", messageId, partyHost.PartyGuid); if (messageRow != null) { if (messageRow.Image.HasValue) { IMedia media = this.Services.MediaService.GetById(messageRow.Image.Value); this.Services.MediaService.Delete(media); } this.DatabaseContext.Database.Delete(messageRow); formResponse.Success = true; } return(formResponse); }
public async Task SubmitResetPasswordForm() { ResetPasswordForm.Submit(); StateHasChanged(); string Code = null; if (QueryHelpers.ParseQuery(new Uri(NavigationManager.Uri).Query).TryGetValue("code", out var value)) { Code = value; } FormResponse Response = await JSRuntime.InvokeAsync <FormResponse>("ResetPassword", ResetPasswordForm.Password, Code); if (Response.Success) { ResetPasswordForm.Succeed(); } else { if (Response.FieldErrors != null) { ResetPasswordForm.Fail(Response.FieldErrors[0]); } else { ResetPasswordForm.Fail(Response.Error); } } StateHasChanged(); }
/// <summary> /// /// </summary> /// <param name="request"></param> /// <returns></returns> public FormResponse Any(GetFormRequest request) { var response = new FormResponse(); response.Data = Db.Single <Form>(request.Id); return(response); }
public async Task UpdatePassword() { PasswordForm.Submit(); StateHasChanged(); FormResponse Response = await JSRuntime.InvokeAsync <FormResponse>("UpdatePassword", PasswordForm.OldPassword, PasswordForm.NewPassword); if (Response.Success) { PasswordForm.Succeed(); await JSRuntime.InvokeVoidAsync("Alert", "success", "Password Changed", "Your password has been updated successfully."); PasswordForm.OldPassword = null; PasswordForm.NewPassword = null; ChangingPassword = false; } else { if (Response.FieldErrors != null) { PasswordForm.Fail(Response.FieldErrors[0]); } else { PasswordForm.Fail(Response.Error); } await JSRuntime.InvokeVoidAsync("Alert", "error", "Error", Response.Error); } StateHasChanged(); }
public async Task <ActionResult> Subscribe([FromForm] SubscribeModel model) { // this.ValidateCsrfToken(); if (!this.ModelState.IsValid) { return(BadRequest(new FormResponse { Message = string.Join(", ", this.ModelState.Values.SelectMany(v => v.Errors).Select(error => error.ErrorMessage)), Result = this.ModelState.AsApiResult() })); } try { var emailGrain = this.grainClient.GetGrain <IEmailGrain>(0); await emailGrain.SendEmail(new Email { To = new List <string> { "*****@*****.**" }, MessageBody = $"<p>Keep me informed: {model.Email}</p>", Subject = $"Testing: subscriber request for {model.Email}", }); return(Ok(new FormResponse { Message = "Geregistreerd!", Result = ApiResult.AsSuccess() })); } catch (Exception e) { var result = new FormResponse { Result = ApiResult.AsException(e, includeExceptions: true), Message = "An Error occurred :-(" }; return(BadRequest(result)); } }
public JsonResult HandlePartyImageForm(PartyImageForm partyImageForm) { FormResponse formResponse = new FormResponse(); if (this.ModelState.IsValid) { PartyHost partyHost = (PartyHost)this.Members.GetCurrentPartier(); IPartyImage partyImage = (IPartyImage)this.Umbraco.TypedMedia(partyImageForm.PartyImage); // if new image is a csm default and old is a custom upload, then delete the custom upload if (partyImage is Image & partyHost.PartyImage is PartyImage) { partyHost.PartyImage = null; } // set new partyHost.PartyImage = partyImage; formResponse.Success = true; } else { formResponse.Errors = this.ModelState.GetErrors(); } return(Json(formResponse, "text/plain")); }
public async Task UpdateProfile() { ProfileForm.Submit(); StateHasChanged(); FormResponse ProfileUpdateResponse = await JSRuntime.InvokeAsync <FormResponse>("UpdateProfile", ProfileForm.Name, ProfileForm.Email); if (ProfileUpdateResponse.Success) { ProfileForm.Succeed(); if (ProfileForm.Email != CurrentUser.Email) { await JSRuntime.InvokeVoidAsync("Alert", "success", "Profile Updated", "Your profile has been updated. Check your email for a new verification code."); } else { await JSRuntime.InvokeVoidAsync("Alert", "success", "Profile Updated", "Your profile has been updated."); } await RefreshProfile(); } else { if (ProfileUpdateResponse.FieldErrors != null) { ProfileForm.Fail(ProfileUpdateResponse.FieldErrors[0]); } else { ProfileForm.Fail(ProfileUpdateResponse.Error); } await JSRuntime.InvokeVoidAsync("Alert", "error", "Error", ProfileUpdateResponse.Error); } StateHasChanged(); }
public ActionResult HandleProfileChangePasswordForm(ProfileChangePasswordForm profileChangePasswordForm) { FormResponse formResponse = new FormResponse(); if (this.ModelState.IsValid) { IPartier partier = this.Members.GetCurrentPartier(); // IMPORTANT ! TODO: check existing password IMember member = this.Services.MemberService.GetById(partier.Id); if (member != null) { this.Services.MemberService.SavePassword(member, profileChangePasswordForm.Password); } formResponse.Success = true; } else { formResponse.Errors = this.ModelState.GetErrors(); } return(Json(formResponse, "text/plain")); }
public async Task FormResponseService_AddFormResponseInvalid_ResultInvalid() { //arrange FormBuild formBuild = new FormBuild("Teste", DateTime.Now); IntFieldBuilder intField = new IntFieldBuilder("value_test", 5, 10, true); TextFieldBuilder textField = new TextFieldBuilder("text", isRequired: true); formBuild.AddField(textField); formBuild.AddField(intField); FormResponse formResponse = new FormResponse(formBuild); IntFieldResponse intResponse = new IntFieldResponse(intField); intResponse.SetValue(11); TextFieldResponse textResponse = new TextFieldResponse(textField); formResponse.AddField(intResponse); formResponse.AddField(textResponse); //act ValidationResult result = await _service.AddAsync(formResponse); //assert Assert.False(result.IsValid, "Formulário não está válido"); }
public ActionResult Index(FormResponse response) { ViewBag.Title = "Weather Lookup"; string zipcode = Request.Form["zipcode"]; ApiClient call = new ApiClient(zipcode); return(View("Weather", call)); }
public Task Handle(FormResponse response) { _log.LogInformation("FakeHandler 1 invoked"); //var responseHelper = new FormResponseJsonHelper(response.ResponseJson); return(Task.CompletedTask); }
public ValidationResult Update(FormResponse formResponse) { ValidationResult result = formResponse.Validate(); if (result.IsValid) { _repository.Update(formResponse); } return(result); }
public async Task <ValidationResult> AddAsync(FormResponse formResponse) { ValidationResult result = formResponse.Validate(); if (result.IsValid) { await _repository.AddAsync(formResponse); } return(result); }
public Task <IFormResponse> SubmitAsync(FormModel model) { IFormResponse result = new FormResponse { Success = true, Errors = "", Result = model }; return(Task.FromResult(result)); }
public IActionResult Delete(int responseId) { EFRepository repo = new EFRepository(context); FormResponse deletedProduct = repo.DeleteResponse(responseId); if (deletedProduct != null) { TempData["message"] = $"{deletedProduct.Name} was deleted"; } return(RedirectToAction("ListResponses")); }
public void FormResponse_Success() { //arrange FormBuild formBuild = new FormBuild("Teste", DateTime.Now); FormResponse formResponse = new FormResponse(formBuild); //act ValidationResult result = formResponse.Validate(); //assert Assert.True(result.IsValid, "Formulário não está válido"); }
public IActionResult Delete(int deletestuff) { FormResponse x = context.Movie.Single(x => x.MovieID == deletestuff); if (ModelState.IsValid) { context.Movie.Remove(x); context.SaveChanges(); } //returns the movie list view return(RedirectToAction("MovieList")); }
public FormResponse DeleteResponse(int reponseId) { FormResponse dbEntry = context.responses.FirstOrDefault(p => p.Id == reponseId); if (dbEntry != null) { context.responses.Remove(dbEntry); context.SaveChanges(); } return(dbEntry); }
public async Task FormResponseRepository_AddNew_Success() { FormBuild formBuild = new FormBuild("Teste", DateTime.Now); FormResponse formResponse = new FormResponse(formBuild); //act await _repository.AddAsync(formResponse); await _unitOfWork.SaveChangesAsync(); //assert Assert.True(formResponse.Id > 0); }
public IActionResult MovieForm(FormResponse Fresponse) { if (ModelState.IsValid) { //context.Movie.Add(Fresponse); //context.SaveChanges(); } return(View("MovieList", new MovieViewModel { //movie = context.Movie.Where(x => x.Title != null) })); }
public IActionResult Movies(FormResponse appResponse) { //makes it so the fields are required if (ModelState.IsValid) { context.Movie.Add(appResponse); context.SaveChanges(); //return View("Confirmation", appResponse); } //else //{ return(View()); //} }
public JsonResult HandlePartyDetailsForm(PartyDetailsForm partyDetailsForm) { FormResponse formResponse = new FormResponse(); if (this.ModelState.IsValid) { PartyHost partyHost = (PartyHost)this.Members.GetCurrentMember(); bool updateDotMailer = false; if (partyHost.PartyHeading != partyDetailsForm.PartyHeading) { partyHost.PartyHeading = partyDetailsForm.PartyHeading; } if (partyHost.PartyDateTime != partyDetailsForm.PartyDateTime) { partyHost.PartyDateTime = partyDetailsForm.PartyDateTime; updateDotMailer = true; } Address address = new Address( partyDetailsForm.Address1, partyDetailsForm.Address2, partyDetailsForm.TownCity, partyDetailsForm.Postcode); if (partyHost.PartyAddress.ToString() != address.ToString()) { partyHost.PartyAddress = address; updateDotMailer = true; } if (updateDotMailer) { DotMailerService.UpdatePartyDetails(partyHost); } formResponse.Success = true; } else { formResponse.Errors = this.ModelState.GetErrors(); } return(Json(formResponse, "text/plain")); }
public ViewResult BursaryForm(FormResponse formResponse) { EFRepository repository = new EFRepository(context); if (ModelState.IsValid) { repository.AddResponse(formResponse); return(View("Thanks", formResponse)); } else { //There is a validation error in the form return(View()); } }
public ActionResult HandleProfileImageForm(ProfileImageForm profileImageForm) { FormResponse formResponse = new FormResponse(); if (this.ModelState.IsValid) { formResponse.Success = true; IPartier partier = this.Members.GetCurrentPartier(); if (profileImageForm.ProfileImage != null && profileImageForm.ProfileImage.ContentLength > 0 && profileImageForm.ProfileImage.InputStream.IsImage()) { ProfileImage profileImage = partier.ProfileImage; string url = string.Empty; if (profileImage == null) { // create new profile image profileImage = ProfileImages.CreateProfileImage(profileImageForm.ProfileImage); // get the new url url = profileImage.Url; // update pointer on partier partier.ProfileImage = profileImage; } else { // update existing profile image url = profileImage.UploadImage(profileImageForm.ProfileImage); } formResponse.Message = JsonConvert.SerializeObject(new { id = profileImage.Id, url = url }); //TODO:S3URL } else // remove reference to image { // this will cause the file deletion partier.ProfileImage = null; } } else { formResponse.Errors = this.ModelState.GetErrors(); } return(Json(formResponse, "text/plain")); }