Esempio n. 1
0
        /// <summary>
        ///     To the azure model.
        /// </summary>
        /// <param name="commonPlace">The common place.</param>
        /// <returns>CommonPlaceAliaseAzure.</returns>
        public static CommonPlaceAliasAzure ToAzureModel(this CommonPlaceAlias commonPlace)
        {
            var azureModel = new CommonPlaceAliasAzure();

            commonPlace.CopyTo(azureModel);

            return(azureModel);
        }
        private async Task <IEnumerable <CommonPlaceAzure> > GetCommonPlacesForAlias(
            string uniquePlaceId,
            CommonPlaceAlias alias)
        {
            //  var nameFilter = TableQuery.GenerateFilterCondition("Name", QueryComparisons.Equal, alias.FullName);
            //var fullFilter = TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, uniquePlaceId.GetFilterById());

            var commonPlaces =
                await _azureManager.GetEntitiesAsync(new TableQuery <CommonPlaceAzure>().Where(uniquePlaceId.GetFilterById()));

            return(commonPlaces.Where(t => t.Name == alias.FullName));
        }
Esempio n. 3
0
        /// <summary>
        ///     Froms the azure model.
        /// </summary>
        /// <param name="azureModel">The azure model.</param>
        /// <returns>CommonPlaceAliace.</returns>
        public static CommonPlaceAlias FromAzureModel(this CommonPlaceAliasAzure azureModel)
        {
            if (azureModel == null)
            {
                return(null);
            }

            var domainModel = new CommonPlaceAlias();

            azureModel.CopyTo(domainModel);

            return(domainModel);
        }
        /// <summary>
        ///     Updates the name of the aliase.
        /// </summary>
        /// <param name="alias">The alias.</param>
        /// <returns>Task{OperationResult}.</returns>
        public async Task <OperationResult> UpdateAliaseName(CommonPlaceAlias alias)
        {
            var currentAlias =
                await
                Task.Factory.StartNew(() => _commonPlaceAliases.FirstOrDefault(c => c.ShortName == alias.ShortName));

            if (currentAlias == null)
            {
                return(new OperationResult(OperationResultStatus.Error, "No aliase for update"));
            }

            currentAlias.FullName = alias.FullName;
            return(new OperationResult(OperationResultStatus.Success));
        }
        /// <summary>
        ///     Updates the name of the aliase.
        /// </summary>
        /// <param name="alias">The alias.</param>
        /// <returns>Task{OperationResult}.</returns>
        public async Task <OperationResult> UpdateAliaseName(CommonPlaceAlias alias)
        {
            var updatedAlias = alias.ToAzureModel();
            var aliasAzure   =
                await
                _azureManager.GetEntityByIdAndRowKeyAsync <CommonPlaceAliasAzure>(
                    AzureTableConstants.CommonPlacesAliasesPartitionKey,
                    updatedAlias.ShortName);

            if (aliasAzure == null)
            {
                return(new OperationResult(OperationResultStatus.Error, "No aliase for update"));
            }

            updatedAlias.CopyToTableEntity(aliasAzure);
            var updateResult = await _azureManager.UpdateEntityAsync(aliasAzure);

            return(updateResult);
        }
Esempio n. 6
0
        private async Task <ActionResult> AddUpdateMission(MissionUi mission, bool createOperation)
        {
            if (ModelState.IsValid)
            {
                OperationResult result;
                if (mission.ExecutionType == ExecutionType.CommonPlace)
                {
                    if (createOperation)
                    {
                        var aliasExist = await _commonPlacesService.CheckAliasExist(mission.CommonPlaceAlias);

                        if (aliasExist)
                        {
                            ViewBag.PersonQualities = await _personQualityService.GetPersonQualities();

                            ModelState.AddModelError("CommonPlaceAlias", "Указанное имя уже используется");
                            return(await ErrorResult(mission));
                        }

                        result = await _commonPlacesService.AddAlias(new CommonPlaceAlias(mission.CommonPlaceAlias));

                        if (result.Status != OperationResultStatus.Success)
                        {
                            ViewBag.PersonQualities = await _personQualityService.GetPersonQualities();

                            ModelState.AddModelError(string.Empty, result.Description);
                            return(await ErrorResult(mission));
                        }
                    }
                    else
                    {
                        if (!string.Equals(mission.CommonPlaceAlias, mission.InitialCommonPlaceAlias))
                        {
                            var aliasExist = await _commonPlacesService.CheckAliasExist(mission.CommonPlaceAlias);

                            if (aliasExist)
                            {
                                ViewBag.PersonQualities = await _personQualityService.GetPersonQualities();

                                ModelState.AddModelError("CommonPlaceAlias", "Указанное имя уже используется");
                                return(await ErrorResult(mission));
                            }

                            if (string.IsNullOrEmpty(mission.InitialCommonPlaceAlias))
                            {
                                result =
                                    await _commonPlacesService.AddAlias(new CommonPlaceAlias(mission.CommonPlaceAlias));

                                if (result.Status != OperationResultStatus.Success)
                                {
                                    ViewBag.PersonQualities = await _personQualityService.GetPersonQualities();

                                    ModelState.AddModelError(string.Empty, result.Description);
                                    return(await ErrorResult(mission));
                                }
                            }
                            else
                            {
                                var oldAlias = new CommonPlaceAlias(mission.InitialCommonPlaceAlias)
                                {
                                    FullName =
                                        mission
                                        .CommonPlaceAlias
                                };
                                result = await _commonPlacesService.UpdateAliaseName(oldAlias);

                                if (result.Status != OperationResultStatus.Success)
                                {
                                    ViewBag.PersonQualities = await _personQualityService.GetPersonQualities();

                                    ModelState.AddModelError(string.Empty, result.Description);
                                    return(await ErrorResult(mission));
                                }
                            }
                        }
                    }
                }

                result = createOperation
                             ? await _missionService.AddNewMission(mission.ConvertToDomain())
                             : await _missionService.UpdateMission(mission.ConvertToDomain());

                if (result.Status != OperationResultStatus.Success)
                {
                    ModelState.AddModelError(string.Empty, result.Description);
                    return(await ErrorResult(mission));
                }

                return(RedirectToAction("Index"));
            }


            return(await ErrorResult(mission));
        }
        /// <summary>
        ///     Adds the alias.
        /// </summary>
        /// <param name="alias">The alias.</param>
        /// <returns>Task{AddResult}.</returns>
        public async Task <IdResult> AddAlias(CommonPlaceAlias alias)
        {
            var azureModel = alias.ToAzureModel();

            return(await _azureManager.AddEntityAsync(azureModel));
        }
Esempio n. 8
0
 /// <summary>
 ///     Adds the alias.
 /// </summary>
 /// <param name="alias">The alias.</param>
 /// <returns>Task{AddResult}.</returns>
 public async Task <IdResult> AddAlias(CommonPlaceAlias alias)
 {
     return(await _commonPlacesRepository.AddAlias(alias));
 }
Esempio n. 9
0
 /// <summary>
 ///     Updates the name of the aliase.
 /// </summary>
 /// <param name="alias">The alias.</param>
 /// <returns>Task{OperationResult}.</returns>
 public async Task <OperationResult> UpdateAliaseName(CommonPlaceAlias alias)
 {
     return(await _commonPlacesRepository.UpdateAliaseName(alias));
 }
 private List <CommonPlace> GetCommonPlacesForAlias(string uniquePlaceId, CommonPlaceAlias @alias)
 {
     return(_commonPlaces.Where(c => c.SettlementId == uniquePlaceId && c.Name == alias.FullName).ToList());
 }
        /// <summary>
        ///     Adds the alias.
        /// </summary>
        /// <param name="alias">The alias.</param>
        /// <returns>Task{AddResult}.</returns>
        public async Task <IdResult> AddAlias(CommonPlaceAlias alias)
        {
            await Task.Factory.StartNew(() => _commonPlaceAliases.Add(alias));

            return(new IdResult(alias.ShortName));
        }