Ejemplo n.º 1
0
        public async Task <ActionResult> CreateMissionFromDraft(string id)
        {
            var missionDraft = await _missionDraftService.GetMissionDraft(id);

            if (missionDraft == null)
            {
                return(HttpNotFound());
            }

            var result = await _missionService.AddNewMission(missionDraft);

            if (result.Status == OperationResultStatus.Success)
            {
                await _missionDraftService.DeleteMissionDraft(id);

                return(RedirectToAction("Index"));
            }
            ViewBag.PersonQualities = await _personQualityService.GetPersonQualities();

            return(View("Details", missionDraft));
        }
Ejemplo n.º 2
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));
        }