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); }
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); }