public ActionResult <MissionCreateDto> CreateMission(MissionCreateDto missionCreateDto)
        {
            var mission = _mapper.Map <Mission>(missionCreateDto);

            mission.OperationId = _operationRepository.GetActiveOperationId(UserId);
            _missionRepository.Create(mission);
            _missionRepository.SaveChanges();
            var missionReadDto = _mapper.Map <Mission>(mission);

            _notificationHub.Clients.All.SendAsync("SendMessage", "MissionCreated");
            _notificationHub.Clients.All.SendAsync("Notification", "Вам назначена миссия #" + mission.Id + ".");
            return(CreatedAtRoute(nameof(GetMissionById), new { Id = missionReadDto.Id }, missionReadDto)); //Return 201
        }
Exemplo n.º 2
0
        public async Task <MissionSimpleDto> Create()
        {
            MissionCreateDto Mission = new MissionCreateDto {
                Name = Name, Deadline = Deadline, Description = Description, TotalSum = TotalSum
            };

            MissionCreating = true;
            MissionRepository repository = new MissionRepository();
            MissionSimpleDto  mission    = await repository.CreateForList(Mission);

            (Application.Current.MainPage.BindingContext as MissionListViewModel).Missions.Add(mission);
            MissionCreating = false;
            await CloseModal();

            return(mission);
        }
Exemplo n.º 3
0
        public async Task <MissionSimpleDto> CreateForList(MissionCreateDto mission)
        {
            Mission dbMission = new Mission
            {
                Name        = mission.Name,
                Deadline    = mission.Deadline,
                Description = mission.Description,
                TotalSum    = mission.TotalSum
            };
            string json       = GetJsonString(dbMission);
            string controller = $"{typeof(Mission).Name.ToLower()}s";
            string UriString  = $"{BaseUrl}/{controller}/create";

            using (HttpClient client = new HttpClient())
            {
                using (HttpContent content = new StringContent(json))
                {
                    using (HttpRequestMessage request = new HttpRequestMessage())
                    {
                        request.RequestUri = new Uri(UriString);
                        request.Method     = HttpMethod.Post;
                        request.Content    = content;

                        using (HttpResponseMessage response = await client.SendAsync(request))
                        {
                            if (response.StatusCode == HttpStatusCode.OK)
                            {
                                string responseString = await response.Content.ReadAsStringAsync();

                                MissionSimpleDto dto = GetItemFromJson <MissionSimpleDto>(responseString);
                                return(dto);
                            }
                            else
                            {
                                string errorResponseString = await response.Content.ReadAsStringAsync();
                            }
                        }
                    }
                }
            }
            return(null);
        }