Пример #1
0
        public async Task <ActionResult> UpdateList([Bind(Include = "Id,Name")] Models.Api.List list)
        {
            if (ModelState.IsValid)
            {
                var updated = await _listsService.UpdateList(list);

                return(RedirectToAction("Index", new { list = list.Id })); // todo: handle errors, show success messages, etc
            }
            return(RedirectToAction("Index"));
        }
Пример #2
0
        public async Task <ActionResult> Edit([Bind(Include = "Id,Name")] Models.Api.List list)
        {
            if (ModelState.IsValid)
            {
                await _listsService.UpdateList(list);

                return(RedirectToAction("Index"));
            }

            return(View(list));
        }
Пример #3
0
        public async Task <bool> UpdateList(Models.Api.List list)
        {
            using (HttpClient client = new HttpClient())
            {
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                var                 json     = JsonConvert.SerializeObject(list);
                StringContent       content  = new StringContent(json, Encoding.UTF8, "application/json");
                HttpResponseMessage response = await client.PutAsync(ListsResource + $"/{list.Id}", content);

                return(response.IsSuccessStatusCode);
            }
        }
Пример #4
0
        public async Task <ActionResult> Create([Bind(Include = "Name")] Models.Api.List list)
        {
            if (ModelState.IsValid)
            {
                var result = await _listsService.CreateList(list);

                if (result.success)
                {
                    return(RedirectToAction("Index", "Home", new { list = result.newListId }));
                }
            }
            return(RedirectToAction("Index", "Home"));
        }
Пример #5
0
        public async Task <ActionResult> Update([Bind(Include = "Id,Name")] Models.Api.List list)
        {
            if (ModelState.IsValid)
            {
                var existingList = await _listsService.GetList(list.Id); //Inlcudes all tasks which we are not changing

                if (existingList != null)
                {
                    existingList.Name = list.Name;
                    await _listsService.UpdateList(existingList);

                    return(RedirectToAction("Index", "Home", new { list = existingList.Id }));
                }
            }
            return(RedirectToAction("Index", "Home"));
        }
Пример #6
0
        public async Task <Models.Api.List> GetList(string Id)
        {
            Models.Api.List lst = null;

            using (HttpClient client = new HttpClient())
            {
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                HttpResponseMessage response = await client.GetAsync(ListsResource + $"/{Id}");

                if (response.IsSuccessStatusCode)
                {
                    var stringContent = await response.Content.ReadAsStringAsync();

                    lst = JsonConvert.DeserializeObject <Models.Api.List>(stringContent);
                }
            }
            return(lst);
        }
Пример #7
0
        public async Task <(bool success, string newListId)> CreateList(Models.Api.List list)
        {
            using (HttpClient client = new HttpClient())
            {
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                var                 json     = JsonConvert.SerializeObject(list);
                StringContent       content  = new StringContent(json, Encoding.UTF8, "application/json");
                HttpResponseMessage response = await client.PostAsync(ListsResource, content);

                if (response.IsSuccessStatusCode)
                {
                    var responseString = await response.Content.ReadAsStringAsync();

                    var outputList = JsonConvert.DeserializeObject <Models.Api.List>(responseString);
                    return(success : true, newListId : outputList.Id);
                }
                else
                {
                    return(success : false, newListId : "");
                }
            }
        }