private async Task FillUsers() { var personQuality = new PersonQuality { Id = "PersonQuality1", Name = "Холерик" }; var personQualityWithScore = new PersonQualityIdWithScore { PersonQualityId = personQuality.Id, Score = 2 }; var repo = IocConfig.GetConfiguredContainer().Resolve <IUserRepository>(); await repo.AddUser( new User { Id = "User1Id", AvatarUrl = "http://cs540104.vk.me/c540102/v540102420/e88c/P64liS_pPNk.jpg", DateOfBirth = new DateTime(1990, 1, 1), NickName = "John", HomeCoordinate = new GeoCoordinate(53.9, 27.56667, 199), KindScale = 87, Points = 120, EnablePushNotifications = true, Level = 7, Sex = Sex.Male, PersonQualitiesWithScores = new List <PersonQualityIdWithScore> { personQualityWithScore } }); }
/// <summary> /// Converts PersonQuality to PersonQualityAzure. /// </summary> /// <param name="personQuality">Type of the person.</param> /// <returns>PersonQualityAzure.</returns> public static PersonQualityAzure ToAzureModel(this PersonQuality personQuality) { var azureModel = new PersonQualityAzure(); personQuality.CopyTo(azureModel); return(azureModel); }
/// <summary> /// The add personQuality. /// </summary> /// <param name="personQuality"> /// The personQuality. /// </param> /// <returns> /// The <see cref="Task"/>. /// </returns> public async Task <IdResult> AddPersonQuality(PersonQuality personQuality) { personQuality.Id = Guid.NewGuid().ToString(); await Task.Factory.StartNew(() => _allPersonQualities.Add(personQuality)); return(new IdResult(personQuality.Id)); }
public async Task <ActionResult> Edit(PersonQuality personQuality) { if (personQuality != null && ModelState.IsValid) { await _personQualityService.UpdatePersonQuality(personQuality); return(RedirectToAction("Index")); } return(View(personQuality)); }
/// <summary> /// The update personQuality. /// </summary> /// <param name="personQuality"> /// The personQuality. /// </param> /// <returns> /// The <see cref="Task"/>. /// </returns> public async Task <OperationResult> UpdatePersonQuality(PersonQuality personQuality) { var existingPersonQuality = await GetPersonQuality(personQuality.Id); if (existingPersonQuality == null) { return(OperationResult.NotFound); } personQuality.CopyTo(existingPersonQuality); return(new OperationResult(OperationResultStatus.Success)); }
/// <summary> /// Converts PersonQualityAzure to PersonQuality. /// </summary> /// <param name="azureModel">The azure model.</param> /// <returns>PersonQuality.</returns> public static PersonQuality FromAzureModel(this PersonQualityAzure azureModel) { if (azureModel == null) { return(null); } var domainModel = new PersonQuality(); azureModel.CopyTo(domainModel); return(domainModel); }
public async Task <ActionResult> Create(PersonQuality personQuality) { FixModelAndModelState(personQuality); if (personQuality != null && ModelState.IsValid) { await _personQualityService.AddNewPersonQuality(personQuality); return(RedirectToAction("Index")); } return(View(personQuality)); }
public async Task Edit_view() { // Действие var result = (await _controller.Index(null)) as ViewResult; var personQualities = result.Model as IEnumerable <PersonQuality>; PersonQuality personQuality = personQualities.First(); result = (await _controller.Edit(personQuality.Id)) as ViewResult; var editDraft = result.Model as PersonQuality; // Утверждение Assert.IsNotNull(editDraft); Assert.AreEqual(editDraft.Id, personQuality.Id); }
public async Task Delete() { // Действие var result = (await _controller.Index(null)) as ViewResult; var personQualities = result.Model as IEnumerable <PersonQuality>; int personQualitiesCount = personQualities.Count(); PersonQuality personQuality = personQualities.First(); var deleteResult = (await _controller.DeleteConfirmed(personQuality.Id)) as RedirectToRouteResult; result = (await _controller.Index(null)) as ViewResult; var personQualitiesAfterDelete = result.Model as IEnumerable <PersonQuality>; // Утверждение Assert.IsNotNull(personQualitiesAfterDelete); Assert.IsNotEmpty(personQualitiesAfterDelete); Assert.AreEqual(personQualitiesCount - 1, personQualitiesAfterDelete.Count()); }
public async Task Create() { // Действие var result = (await _controller.Index(null)) as ViewResult; var personQualities = result.Model as IEnumerable <PersonQuality>; int count = personQualities.Count(); var newPersonQuality = new PersonQuality { Name = "New personQuality", Description = "Description" }; result = (await _controller.Create(newPersonQuality)) as ViewResult; // Утверждение Assert.IsNotNull(personQualities); Assert.IsNotEmpty(personQualities); Assert.AreEqual(personQualities.Last().Name, "New personQuality"); Assert.AreEqual(count + 1, personQualities.Count()); }
/// <summary> /// Updates the type of the person. /// </summary> /// <param name="personQuality">The mission.</param> /// <returns>Task{OperationResult}.</returns> public async Task <OperationResult> UpdatePersonQuality(PersonQuality personQuality) { var updatedPersonQuality = personQuality.ToAzureModel(); var personQualityAzure = await _azureManager.GetEntityByIdAndRowKeyAsync <PersonQualityAzure>( updatedPersonQuality.PartitionKey, updatedPersonQuality.RowKey); if (personQualityAzure == null) { return(new OperationResult(OperationResultStatus.Error, "No person quality for update")); } updatedPersonQuality.CopyToTableEntity(personQualityAzure); var updateResult = await _azureManager.UpdateEntityAsync(personQualityAzure); if (updateResult.Status == OperationResultStatus.Success) { var warnings = new StringBuilder(); foreach (var personQualityDependent in RepositoriesDependentOnPersonQuality) { var refreshMissionDraftsResult = await personQualityDependent.UpdateLinksToPersonQuality(personQualityAzure.Id, personQualityAzure.Name); if (refreshMissionDraftsResult.Status != OperationResultStatus.Success) { var warning = $"Links to updated person quality are not refreshed in {personQualityDependent.GetType().Name}! "; warnings.AppendLine(warning); } } if (warnings.Length > 0) { return(new OperationResult(OperationResultStatus.Warning, warnings.ToString())); } } return(updateResult); }
public async Task Edit() { // Действие var result = (await _controller.Index(null)) as ViewResult; var personQualities = result.Model as IEnumerable <PersonQuality>; PersonQuality oldDraft = personQualities.First(); var personQuality = new PersonQuality { Id = oldDraft.Id, Name = "Updated personQuality", Description = oldDraft.Description }; var editResult = (await _controller.Edit(personQuality)) as RedirectToRouteResult; result = (await _controller.Details(oldDraft.Id)) as ViewResult; var personQualityAfterEdit = result.Model as PersonQuality; // Утверждение Assert.IsNotNull(editResult); Assert.IsNotNull(personQualities); Assert.IsNotEmpty(personQualities); Assert.AreEqual("Updated personQuality", personQualityAfterEdit.Name); }
/// <summary> /// The add new mission draft. /// </summary> /// <param name="personQuality"> /// The mission draft. /// </param> /// <returns> /// The <see cref="Task"/>. /// </returns> public Task <IdResult> AddNewPersonQuality(PersonQuality personQuality) { return(_personQualityRepository.AddPersonQuality(personQuality)); }
/// <summary> /// The update mission draft. /// </summary> /// <param name="personQuality"> /// The mission draft. /// </param> /// <returns> /// The <see cref="Task"/>. /// </returns> public Task <OperationResult> UpdatePersonQuality(PersonQuality personQuality) { return(_personQualityRepository.UpdatePersonQuality(personQuality)); }
/// <summary> /// Adds the type of the person. /// </summary> /// <param name="personQuality">Type of the person.</param> /// <returns>Task{AddResult}.</returns> public async Task <IdResult> AddPersonQuality(PersonQuality personQuality) { personQuality.Id = Guid.NewGuid().ToString("N"); return(await _azureManager.AddEntityAsync(personQuality.ToAzureModel())); }
/// <summary> /// Initializes a new instance of the <see cref="UserRepository" /> class. /// </summary> public UserRepository() { if (!_allUsers.Any()) { var personQuality = new PersonQuality { Id = GameConstants.PersonQuality.ActivityQualityId, Name = "Активность" }; var personQualityWithScore = new PersonQualityIdWithScore { PersonQualityId = personQuality.Id, Score = -2 }; var personQuality2 = new PersonQuality { Id = GameConstants.PersonQuality.CommunicationQualityId, Name = "Коммуникативность" }; var personQualityWithScore2 = new PersonQualityIdWithScore { PersonQualityId = personQuality2.Id, Score = 2 }; _allUsers.Add( new User { Id = "User1Id", AvatarUrl = "http://cs540104.vk.me/c540102/v540102420/e88c/P64liS_pPNk.jpg", DateOfBirth = new DateTime(1990, 1, 1), NickName = "John", HomeCoordinate = new GeoCoordinate(53.9, 27.56667, 199), BaseSouthCoordinate = new GeoCoordinate(53.897863, 27.566649), BaseWestCoordinate = new GeoCoordinate(53.899994, 27.562583), BaseEastCoordinate = new GeoCoordinate(53.900019, 27.570415), BaseNorthCoordinate = new GeoCoordinate(53.902503, 27.566606), Selected2BaseCoordinates = new List <string> { "East", "North" }, RadarCoordinate = new GeoCoordinate(53.900493, 27.567513), KindScale = 87, Points = 120, EnablePushNotifications = true, Level = 7, LevelPoints = 50, Sex = Sex.Male, RadrugaColor = "e27b2f", CityShortName = "Brest", CountryShortName = "Belarus", PersonQualitiesWithScores = new List <PersonQualityIdWithScore> { personQualityWithScore, personQualityWithScore2 }, ActiveMissionIds = new List <MissionIdWithSetId> { new MissionIdWithSetId { MissionId = "Mission1" }, new MissionIdWithSetId { MissionId = "fe9b1f3a-059b-4b4e-8f08-0a22a21a1ed0" }, new MissionIdWithSetId { MissionId = "3c27b903-cf03-447e-9682-f756e70ca908" }, new MissionIdWithSetId { MissionId = "33f075f4-4e8c-47bc-b0d7-9661f4ecdd5d" }, new MissionIdWithSetId { MissionId = "33f075f4-4e8c-47bc-b0d7-9661f4ecdd6d" }, new MissionIdWithSetId { MissionId = "33f075f4-4e8c-47bc-b0d7-9661f4ecdd7d" }, new MissionIdWithSetId { MissionId = "33f075f4-4e8c-47bc-b0d7-9661f4ecdd8d" }, new MissionIdWithSetId { MissionId = "2ddf9168-b030-4b6c-a038-72593e7a75f1" }, new MissionIdWithSetId { MissionId = "2ddf9168-b030-4b6c-a038-72593e7a75f2" }, new MissionIdWithSetId { MissionId = "d061155a-9504-498d-a6e7-bcc20c295cde" }, new MissionIdWithSetId { MissionId = "8ab5fa9b-15a7-49ec-8d5f-2a47d4affd52" }, new MissionIdWithSetId { MissionId = "71130d2e-e513-4b29-ad12-7a368f4d927a" }, new MissionIdWithSetId { MissionId = "19e18c3f-2daa-4e18-bf32-2a1f77fdc73f" }, new MissionIdWithSetId { MissionId = "b23f79fe-08d3-4d24-a293-51f67e2131be" }, new MissionIdWithSetId { MissionId = "524b9f98-88b2-460a-ae3f-e15df4cef2ae" }, new MissionIdWithSetId { MissionId = "2c187275-97c0-4dcf-a1f0-89d7018a03e2" }, new MissionIdWithSetId { MissionId = "3be2d03c-f100-42be-bc9f-54166e108d43" }, new MissionIdWithSetId { MissionId = "8c67c3de-5458-4c6a-a09e-be2d06cdcb2e" }, new MissionIdWithSetId { MissionId = "68d75498-e44f-4bf8-a2ee-13b4998c17d3" }, new MissionIdWithSetId { MissionId = "68d75498-e44f-4bf8-a2ee-13b4998c17d4" }, new MissionIdWithSetId { MissionId = "68d75498-e44f-4bf8-a2ee-13b4998c17d5" }, new MissionIdWithSetId { MissionId = "68d75498-e44f-4bf8-a2ee-13b4998c17d6" }, new MissionIdWithSetId { MissionId = "68d75498-e44f-4bf8-a2ee-13b4998c17d7" }, new MissionIdWithSetId { MissionId = "68d75498-e44f-4bf8-a2ee-13b4998c1725" }, new MissionIdWithSetId { MissionId = "5823973e-ac62-4efe-9c5d-1755df874d99" } }, ActiveMissionSetIds = new List <string> { GameConstants.MissionSet.FirstSetId, GameConstants.MissionSet.SecondSetId, GameConstants.MissionSet.ThirdSetId }, MissionSetIds = new List <MissionSetIdWithOrder> { new MissionSetIdWithOrder { MissionSetId = GameConstants.MissionSet.FirstSetId, Order = 0 }, new MissionSetIdWithOrder { MissionSetId = GameConstants.MissionSet.SecondSetId, Order = 1 }, new MissionSetIdWithOrder { MissionSetId = GameConstants.MissionSet.ThirdSetId, Order = 2 } } }); _allUsers.Add( new User { Id = "User2Id", AvatarUrl = "https://pp.vk.me/c622726/v622726000/276d6/g6W5sDwP0jc.jpg", DateOfBirth = new DateTime(1990, 1, 1), NickName = "Jim", HomeCoordinate = new GeoCoordinate(55.5554, 28.7778), KindScale = 87, Points = 60, EnablePushNotifications = true, Level = 7, LevelPoints = 50, Sex = Sex.Male, RadrugaColor = "e27b2f", PersonQualitiesWithScores = new List <PersonQualityIdWithScore> { personQualityWithScore, personQualityWithScore2 }, ActiveMissionIds = new List <MissionIdWithSetId> { new MissionIdWithSetId { MissionId = "Mission1" }, new MissionIdWithSetId { MissionId = "Mission2" } }, ActiveMissionSetIds = new List <string> { GameConstants.MissionSet.FirstSetId, GameConstants.MissionSet.SecondSetId, GameConstants.MissionSet.ThirdSetId }, MissionSetIds = new List <MissionSetIdWithOrder> { new MissionSetIdWithOrder { MissionSetId = GameConstants.MissionSet.FirstSetId, Order = 0 }, new MissionSetIdWithOrder { MissionSetId = GameConstants.MissionSet.SecondSetId, Order = 1 } } }); } }
/// <summary> /// Fixes the state of the model and model. /// </summary> /// <param name="personQuality"> /// The person quality. /// </param> private void FixModelAndModelState(PersonQuality personQuality) { Trace.TraceInformation("{0}", personQuality); ModelState.Remove("Id"); }