public static ActionConfirmation CreateSuccessConfirmation(string message) { var confirmation = new ActionConfirmation(); confirmation.Message = message; confirmation.WasSuccessful = true; return confirmation; }
public static ActionConfirmation CreateFailureConfirmation(string message) { var confirmation = new ActionConfirmation(); confirmation.Message = message; confirmation.WasSuccessful = false; return confirmation; }
public void CannotUpdateWithInvalidChannelsSlideFromForm() { // Establish Context ChannelsSlide invalidChannelsSlideFromForm = new ChannelsSlide(); // Intentionally empty to ensure successful transfer of values ChannelsSlide channelsSlideFromDb = new ChannelsSlide(); channelsSlideRepository.Expect(r => r.Get(1)) .Return(channelsSlideFromDb); // Act ActionConfirmation confirmation = channelsSlideManagementService.UpdateWith(invalidChannelsSlideFromForm, 1); // Assert confirmation.ShouldNotBeNull(); confirmation.WasSuccessful.ShouldBeFalse(); confirmation.Value.ShouldBeNull(); }
public ActionConfirmation SaveOrUpdate(Channel channel) { if (channel.IsValid()) { channelRepository.SaveOrUpdate(channel); ActionConfirmation saveOrUpdateConfirmation = ActionConfirmation.CreateSuccessConfirmation( "The channel was successfully saved."); saveOrUpdateConfirmation.Value = channel; return(saveOrUpdateConfirmation); } else { channelRepository.DbContext.RollbackTransaction(); return(ActionConfirmation.CreateFailureConfirmation( "The channel could not be saved due to missing or invalid information.")); } }
public ActionResult Edit(SlideFolder slideFolder) { if (ViewData.ModelState.IsValid) { ActionConfirmation updateConfirmation = slideFolderManagementService.UpdateWith(slideFolder, slideFolder.Id); if (updateConfirmation.WasSuccessful) { TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()] = updateConfirmation.Message; return(RedirectToAction("Index")); } } SlideFolderFormViewModel viewModel = slideFolderManagementService.CreateFormViewModelFor(slideFolder); return(View(viewModel)); }
public void CannotUpdateWithInvalidHostFromForm() { // Establish Context var invalidHostFromForm = new Host(); // Intentionally empty to ensure successful transfer of values var hostFromDb = new Host(); _hostRepository.Expect(r => r.Get(1)) .Return(hostFromDb); // Act ActionConfirmation confirmation = _hostManagementService.UpdateWith(invalidHostFromForm, 1); // Assert confirmation.ShouldNotBeNull(); confirmation.WasSuccessful.ShouldBeFalse(); confirmation.Value.ShouldBeNull(); }
public ActionConfirmation SaveOrUpdate(Template template) { if (template.IsValid()) { templateRepository.SaveOrUpdate(template); ActionConfirmation saveOrUpdateConfirmation = ActionConfirmation.CreateSuccessConfirmation( "The template was successfully saved."); saveOrUpdateConfirmation.Value = template; return(saveOrUpdateConfirmation); } else { templateRepository.DbContext.RollbackTransaction(); return(ActionConfirmation.CreateFailureConfirmation( "The template could not be saved due to missing or invalid information.")); } }
public void CannotUpdateWithInvalidTemplateFromForm() { // Establish Context Template invalidTemplateFromForm = new Template(); // Intentionally empty to ensure successful transfer of values Template templateFromDb = new Template(); templateRepository.Expect(r => r.Get(1)) .Return(templateFromDb); // Act ActionConfirmation confirmation = templateManagementService.UpdateWith(invalidTemplateFromForm, 1, null, null); // Assert confirmation.ShouldNotBeNull(); confirmation.WasSuccessful.ShouldBeFalse(); confirmation.Value.ShouldBeNull(); }
public ActionConfirmation SaveOrUpdate(SupportTeam supportTeam) { if (supportTeam.IsValid()) { _supportTeamRepository.SaveOrUpdate(supportTeam); ActionConfirmation saveOrUpdateConfirmation = ActionConfirmation.CreateSuccessConfirmation( "The support team was successfully saved."); saveOrUpdateConfirmation.Value = supportTeam; return(saveOrUpdateConfirmation); } else { _supportTeamRepository.DbContext.RollbackTransaction(); return(ActionConfirmation.CreateFailureConfirmation( "The support team could not be saved due to missing or invalid information.")); } }
public ActionConfirmation SaveOrUpdate(AssetContent assetContent) { if (assetContent.IsValid()) { assetContentRepository.SaveOrUpdate(assetContent); ActionConfirmation saveOrUpdateConfirmation = ActionConfirmation.CreateSuccessConfirmation( "The assetContent was successfully saved."); saveOrUpdateConfirmation.Value = assetContent; return(saveOrUpdateConfirmation); } else { assetContentRepository.DbContext.RollbackTransaction(); return(ActionConfirmation.CreateFailureConfirmation( "The assetContent could not be saved due to missing or invalid information.")); } }
public ActionConfirmation SaveOrUpdate(Publisher publisher) { if (publisher.IsValid()) { publisherRepository.SaveOrUpdate(publisher); ActionConfirmation saveOrUpdateConfirmation = ActionConfirmation.CreateSuccessConfirmation( "The publisher was successfully saved."); saveOrUpdateConfirmation.Value = publisher; return(saveOrUpdateConfirmation); } else { publisherRepository.DbContext.RollbackTransaction(); return(ActionConfirmation.CreateFailureConfirmation( "The publisher could not be saved due to missing or invalid information.")); } }
public ActionConfirmation SaveOrUpdate(Host host) { if (host.IsValid()) { ValidateHost(host); _hostRepository.SaveOrUpdate(host); ActionConfirmation saveOrUpdateConfirmation = ActionConfirmation.CreateSuccessConfirmation( "The host was successfully saved."); saveOrUpdateConfirmation.Value = host; return(saveOrUpdateConfirmation); } else { _hostRepository.DbContext.RollbackTransaction(); return(ActionConfirmation.CreateFailureConfirmation( "The host could not be saved due to missing or invalid information.")); } }
public ActionConfirmation SaveOrUpdate(Org org) { if (org.IsValid()) { ValidateOrg(org); _orgRepository.SaveOrUpdate(org); ActionConfirmation saveOrUpdateConfirmation = ActionConfirmation.CreateSuccessConfirmation( "The org was successfully saved."); saveOrUpdateConfirmation.Value = org; return(saveOrUpdateConfirmation); } else { _orgRepository.DbContext.RollbackTransaction(); return(ActionConfirmation.CreateFailureConfirmation( "The org could not be saved due to missing or invalid information.")); } }
public ActionConfirmation SaveOrUpdate(Person person) { if (person.IsValid()) { ValidatePerson(person); _personRepository.SaveOrUpdate(person); ActionConfirmation saveOrUpdateConfirmation = ActionConfirmation.CreateSuccessConfirmation( "The person was successfully saved."); saveOrUpdateConfirmation.Value = person; return(saveOrUpdateConfirmation); } else { _personRepository.DbContext.RollbackTransaction(); return(ActionConfirmation.CreateFailureConfirmation( "The person could not be saved due to missing or invalid information.")); } }
public ActionConfirmation SaveOrUpdate(Agency agency) { if (agency.IsValid()) { ValidateAgency(agency); _agencyRepository.SaveOrUpdate(agency); ActionConfirmation saveOrUpdateConfirmation = ActionConfirmation.CreateSuccessConfirmation( "The agency was successfully saved."); saveOrUpdateConfirmation.Value = agency; return(saveOrUpdateConfirmation); } else { _agencyRepository.DbContext.RollbackTransaction(); return(ActionConfirmation.CreateFailureConfirmation( "The agency could not be saved due to missing or invalid information.")); } }
public ActionResult Create(RSSFeed rSSFeed) { //if (ViewData.ModelState.IsValid) { ActionConfirmation saveOrUpdateConfirmation = rSSFeedManagementService.SaveOrUpdate(rSSFeed); if (saveOrUpdateConfirmation.WasSuccessful) { TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()] = saveOrUpdateConfirmation.Message; return(RedirectToAction("Index")); } //} else { // rSSFeed = null; //} RSSFeedFormViewModel viewModel = rSSFeedManagementService.CreateFormViewModelFor(rSSFeed); return(View(viewModel)); }
public void CanCreateValidTimeEntryFromForm() { // Establish Context var timeEntryFromForm = new TimeEntry(); _timeEntryManagementService.Expect(r => r.SaveOrUpdate(timeEntryFromForm)) .Return(ActionConfirmation.CreateSuccessConfirmation("saved")); _authenticationProvider.Expect(x => x.GetLoggedInUser()).Return("testuser"); _personManagementService.Expect(x => x.GetByUserName(Arg <string> .Is.Anything)).Return( PersonInstanceFactory.CreateValidTransientPerson()); // Act RedirectToRouteResult redirectResult = _timeEntriesController.Create(timeEntryFromForm) .AssertActionRedirect().ToAction("Index"); // Assert _timeEntriesController.TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()].ToString() .ShouldEqual("saved"); }
public ActionResult Edit(SpeechViewModel model) { var currentUserId = this.CurrentUserSessionContext().UserId; if (!_messageService.HasRightToMessage(currentUserId, model.MessageId)) { return(new HttpAccessDeniedResult()); } Message message = _messageService.UpdateSpeech(model.MessageId, model.Mind, model.Speech); if (message != null) { _unitOfWork.Commit(); TempData[ActionConfirmation.TempDataKey] = ActionConfirmation.CreateSuccess("Your speech has been saved."); return(RedirectToActionPermanent("Edit", new { @id = message.Id })); } TempData[ActionConfirmation.TempDataKey] = ActionConfirmation.CreateError("Your speech has not been saved. Try again."); return(View(model)); }
public ActionConfirmation SaveOrUpdate(IdentityUser user) { if (user.IsValid()) { try { _userRepository.SaveOrUpdate(user); _userRepository.DbContext.CommitChanges(); return(ActionConfirmation.CreateSuccess("user saved")); } catch (Exception exception) { return(ActionConfirmation.CreateFailure("error > " + exception.Message)); } } else { return(ActionConfirmation.CreateFailure("user is not valid")); } }
public ActionConfirmation SaveOrUpdate(Application application) { if (application.IsValid()) { application.SetHostsFromHostId(application.HostIds); _applicationRepository.SaveOrUpdate(application); ActionConfirmation saveOrUpdateConfirmation = ActionConfirmation.CreateSuccessConfirmation( "The application was successfully saved."); saveOrUpdateConfirmation.Value = application; return(saveOrUpdateConfirmation); } else { _applicationRepository.DbContext.RollbackTransaction(); return(ActionConfirmation.CreateFailureConfirmation( "The application could not be saved due to missing or invalid information.")); } }
public void CanCreateValidAgencyFromForm() { // Establish Context var agencyFromForm = new Agency(); var testUser = new Person(); testUser.SetAssignedIdTo(1); _agencyManagementService.Expect(r => r.SaveOrUpdate(agencyFromForm)) .Return(ActionConfirmation.CreateSuccessConfirmation("saved")); _authenticationProvider.Expect(r => r.GetLoggedInUser()).Return("user1"); _personManagementService.Expect(r => r.GetByUserName("user1")).Return(testUser); // Act RedirectToRouteResult redirectResult = _agenciesController.Create(agencyFromForm) .AssertActionRedirect().ToAction("Search"); // Assert _agenciesController.TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()].ToString() .ShouldEqual("saved"); }
public ActionConfirmation SaveOrUpdate(Estado estado) { if (!estado.IsValid()) { return(ActionConfirmation.CreateFailure("not valid!")); } try { _statusRepository.SaveOrUpdate(estado); _statusRepository.DbContext.CommitChanges(); return(ActionConfirmation.CreateSuccess("saved ok")); } catch (Exception exception) { _eventLogService.AddException(exception.Message, exception.StackTrace, EventCategory.GuardarObjeto.ToString(), exception, estado.ActualizadoPor, EventSource.Sistema); return(ActionConfirmation.CreateFailure(exception.ToString())); } }
public ActionConfirmation SaveOrUpdate(IdentityRole role) { if (role.IsValid()) { try { _roleRepository.SaveOrUpdate(role); _roleRepository.DbContext.CommitChanges(); return(ActionConfirmation.CreateSuccess("role saved")); } catch (Exception exception) { return(ActionConfirmation.CreateFailure("error > " + exception.Message)); } } else { return(ActionConfirmation.CreateFailure("role is not valid")); } }
public ActionConfirmation SaveOrUpdate(WrmsSystem wrmsSystem) { if (wrmsSystem.IsValid()) { ValidateWrmsSystem(wrmsSystem); _wrmsSystemRepository.SaveOrUpdate(wrmsSystem); ActionConfirmation saveOrUpdateConfirmation = ActionConfirmation.CreateSuccessConfirmation( "The wrmsSystem was successfully saved."); saveOrUpdateConfirmation.Value = wrmsSystem; return(saveOrUpdateConfirmation); } else { _wrmsSystemRepository.DbContext.RollbackTransaction(); return(ActionConfirmation.CreateFailureConfirmation( "The wrmsSystem could not be saved due to missing or invalid information.")); } }
/// <summary> /// Adds the specified activity type. /// </summary> /// <param name = "activityType">Type of the activity.</param> /// <param name = "eventType">Type of the event.</param> /// <param name = "message">The message.</param> /// <param name = "objectId">The object id.</param> /// <param name = "objectType">Type of the object.</param> /// <param name = "username">The username.</param> /// <returns></returns> public ActionConfirmation Add( string activityType, EventType eventType, string message, string objectId, string objectType, string username) { var logItem = new LogItem { Category = EventCategory.Actividad.ToString(), EventDate = DateTime.Now, IsVisible = true, Message = activityType, MessageDescription = message, Username = username, ObjectId = objectId, ObjectType = objectType, EventType = (short)eventType, Source = EventSource.Sistema.ToString() }; ActionConfirmation confirmation; try { _eventLogService.Write(logItem); confirmation = ActionConfirmation.CreateSuccess("Activity Added"); } catch (Exception exception) { _eventLogService.AddException( exception.Message, exception.ToString(), EventCategory.NoDefinida.ToString(), exception); confirmation = ActionConfirmation.CreateFailure("Activity cannot be added > " + exception.Message); } return(confirmation); }
public ActionResult Create(TimeEntry timeEntry) { int userId = GetCurrentUser().Id; timeEntry.LastUpdateTimeStamp = DateTime.Now; timeEntry.LastUpdateUser = userId; timeEntry.UserId = userId; timeEntry.Notes = Server.HtmlEncode(timeEntry.Notes); var timeEntryDateString = string.Empty; if (timeEntry.WeekEndingDate.HasValue) { timeEntryDateString = timeEntry.WeekEndingDate.Value.ToString("MM-dd-yyyy"); } if (ViewData.ModelState.IsValid) { ActionConfirmation saveOrUpdateConfirmation = _timeEntryManagementService.SaveOrUpdate(timeEntry); if (saveOrUpdateConfirmation.WasSuccessful) { TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()] = saveOrUpdateConfirmation.Message; return(RedirectToAction("Index", new RouteValueDictionary(new { action = "Index", date = timeEntryDateString }))); } } else { timeEntry = null; } TimeEntryFormViewModel viewModel = _timeEntryManagementService.CreateFormViewModelFor(timeEntry, _authenticationProvider.GetLoggedInUser()); //return !string.IsNullOrEmpty(timeEntryDateString) ? RedirectToAction(action, new { date = timeEntryDateString }) : RedirectToAction(action); return(RedirectToAction("Index", new RouteValueDictionary(new { action = "Index", date = timeEntryDateString }))); }
/// <param name="fromForm">Must be a not-null, valid object</param> public virtual ActionConfirmation <T> SaveOrUpdate(T fromForm) { if (fromForm == null) { throw new ArgumentNullException("fromForm may not be null"); } if (!DataAnnotationsValidator.TryValidate(fromForm)) { throw new InvalidOperationException("fromForm is in an invalid state"); } // If the ID of fromForm is 0 then we know we're saving a brand new one if (fromForm.IsTransient()) { _entityRepository.SaveOrUpdate(fromForm); return(ActionConfirmation <T> .CreateSuccessConfirmation( "The " + GetFriendlyNameOfType() + " was successfully saved.", fromForm)); } // But if the ID of fromForm is > 0, then we know we're updating an existing one. // Always update the existing one instead of simply "updating" the item from the form. Otherwise, // you risk the loss of important data, such as references not captured by the form or audit // details that exists from when the object was initially saved. T toUpdate = _entityRepository.Get(fromForm.Id); TransferFormValuesTo(toUpdate, fromForm); // Since any changes will be automatically persisted to the DB when the current transaction // is committed, we want to make sure it's in a valid state after being updated. If it's // not, it's most likely a development bug. In design-by-contract speak, this is an "ensure check." if (!DataAnnotationsValidator.TryValidate(toUpdate)) { throw new InvalidOperationException("The " + GetFriendlyNameOfType() + " could not be updated due to missing or invalid information"); } return(ActionConfirmation <T> .CreateSuccessConfirmation( "The " + GetFriendlyNameOfType() + " was successfully updated.", fromForm)); }
public ActionConfirmation Delete(Guid id) { var status = Get(id); if (status == null) { return(ActionConfirmation.CreateFailure("Status no existe")); } try { _statusRepository.Delete(status); return(ActionConfirmation.CreateSuccess("status borrado!")); } catch (System.Exception exception) { _eventLogService.AddException(exception.Message, exception.StackTrace, EventCategory.EliminarObjeto.ToString(), exception, "", EventSource.Sistema); var confirmation = ActionConfirmation.CreateFailure("status no eliminado | " + exception); return(confirmation); } }
public ActionResult Edit(RequestEstimate requestEstimate) { if (ViewData.ModelState.IsValid) { requestEstimate.LastUpdateTimeStamp = DateTime.Now; requestEstimate.LastUpdateUser = GetCurrentUser().Id; ActionConfirmation updateConfirmation = _requestEstimateManagementService.UpdateWith(requestEstimate, requestEstimate.Id); if (updateConfirmation.WasSuccessful) { TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()] = updateConfirmation.Message; return(RedirectToAction("Index")); } } RequestEstimateFormViewModel viewModel = _requestEstimateManagementService.CreateFormViewModelFor(requestEstimate); return(View(viewModel)); }
public ActionConfirmation SaveOrUpdateGeneral(GerenteGeneral gerenteGeneral) { if (!gerenteGeneral.IsValid()) { return(ActionConfirmation.CreateFailure("item no es válido")); } try { _generalRepository.SaveOrUpdate(gerenteGeneral); _generalRepository.DbContext.CommitChanges(); return(ActionConfirmation.CreateSuccess("saved ok")); } catch (Exception exception) { _eventLogService.AddException(exception.Message, exception.StackTrace, EventCategory.GuardarObjeto.ToString(), exception, gerenteGeneral.ActualizadoPor, EventSource.Sistema); return(ActionConfirmation.CreateFailure(exception.ToString())); } }
public ActionConfirmation SaveOrUpdateSistema(Sistema item) { if (!item.IsValid()) { return(ActionConfirmation.CreateFailure("objeto no es válida")); } try { _sistemaRepository.SaveOrUpdate(item); _sistemaRepository.DbContext.CommitChanges(); return(ActionConfirmation.CreateSuccess("saved ok")); } catch (Exception exception) { _eventLogService.AddException(exception.Message, exception.StackTrace, EventCategory.GuardarObjeto.ToString(), exception, item.ActualizadoPor, EventSource.Sistema); return(ActionConfirmation.CreateFailure(exception.ToString())); } }
public ActionConfirmation SaveOrUpdateProvincia(Provincia provincia) { if (!provincia.IsValid()) { ActionConfirmation.CreateFailure("provincia no válida"); } try { _provinciaRepository.SaveOrUpdate(provincia); _provinciaRepository.DbContext.CommitChanges(); return(ActionConfirmation.CreateSuccess("saved ok")); } catch (Exception exception) { _eventLogService.AddException(exception.Message, exception.StackTrace, EventCategory.GuardarObjeto.ToString(), exception, provincia.ActualizadoPor, EventSource.Sistema); return(ActionConfirmation.CreateFailure(exception.ToString())); } }
public void Signup_Action_When_The_User_Model_Is_Valid_Returns_RedirectToRouteResult() { // Arrange const string expectedActionName = "Login"; const string expectedControllerName = "Account"; var registeredUser = new UserRegisterViewModel { Email = "*****@*****.**", Password = "******".Hash() }; var confirmation = new ActionConfirmation<User> { WasSuccessful = true, Message = "", Value = new User() }; _userService.Setup(r => r.AddUser(It.IsAny<User>(), It.IsAny<AccountType>())).Returns(confirmation); _accountController = new AccountController(_userService.Object, _mappingService.Object, _authenticationService.Object); // Act var result = _accountController.Signup(registeredUser) as RedirectToRouteResult; // Assert Assert.IsNotNull(result, "Should have returned a RedirectToRouteResult"); Assert.AreEqual(expectedActionName, result.RouteValues["Action"], "Action name should be {0}", expectedActionName); Assert.AreEqual(expectedControllerName, result.RouteValues["Controller"], "Controller name should be {0}", expectedControllerName); }