public async Task <IActionResult> Edit(Guid id, CPUWatercooler model)
        {
            try
            {
                if (model == null)
                {
                    return(this.NotFound());
                }

                if (model.ImageFile != null)
                {
                    model.ImageTitle = model.ImageFile.FileName;
                    model.ImageData  = ImageManager.GetByteArrayFromImage(model.ImageFile);
                }

                model.CPUWatercoolerId = id;

                string accessToken = await this.HttpContext.GetTokenAsync("access_token");

                await ApiRequests.PutAsync(accessToken, string.Format("{0}/{1}", this.apiBaseUrl, this.apiController), model);

                return(this.RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(this.View());
            }
        }
        public async Task <IActionResult> Create(CPUWatercooler model)
        {
            try
            {
                if (model.ImageFile != null)
                {
                    model.ImageTitle = model.ImageFile.FileName;
                    model.ImageData  = ImageManager.GetByteArrayFromImage(model.ImageFile);
                }

                using (var httpClient = new HttpClient())
                {
                    var content = new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, "application/json");

                    using (HttpResponseMessage response = await httpClient.PostAsync(string.Format("{0}/{1}", this.apiBaseUrl, this.apiController), content))
                    {
                        string apiResponse = await response.Content.ReadAsStringAsync();
                    }
                }

                return(this.RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(this.View());
            }
        }
        // GET: CPUWatercooler/Edit/5
        public async Task <IActionResult> Edit(Guid id)
        {
            string accessToken = await this.HttpContext.GetTokenAsync("access_token");

            string response = await ApiRequests.GetAsync(accessToken, string.Format("{0}/{1}/{2}", this.apiBaseUrl, this.apiController, id));

            CPUWatercooler cpuWatercooler = JsonConvert.DeserializeObject <CPUWatercooler>(response);

            return(this.View(cpuWatercooler));
        }
Beispiel #4
0
        public async Task <ActionResult <CPUWatercooler> > Get(Guid Id)
        {
            CPUWatercooler cpuWatercooler = await this._repository.Get(Id);

            if (cpuWatercooler == null)
            {
                return(this.NotFound());
            }

            return(cpuWatercooler);
        }
        public async Task <IActionResult> Delete(Guid id, CPUWatercooler cpuWatercooler = null)
        {
            try
            {
                string accessToken = await this.HttpContext.GetTokenAsync("access_token");

                await ApiRequests.DeleteAsync(accessToken, string.Format("{0}/{1}/{2}", this.apiBaseUrl, this.apiController, id));

                return(this.RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(this.View());
            }
        }
        // GET: CPUWatercooler/Details/5
        public async Task <IActionResult> Details(Guid id)
        {
            var cpuWatercooler = new CPUWatercooler();

            using (var httpClient = new HttpClient())
            {
                using (HttpResponseMessage response = await httpClient.GetAsync(string.Format("{0}/{1}/{2}", this.apiBaseUrl, this.apiController, id)))
                {
                    string apiResponse = await response.Content.ReadAsStringAsync();

                    cpuWatercooler = JsonConvert.DeserializeObject <CPUWatercooler>(apiResponse);
                }
            }

            return(this.View(cpuWatercooler));
        }
Beispiel #7
0
        public async Task <ActionResult <CPUWatercooler> > Post([FromBody] CPUWatercooler model)
        {
            try
            {
                model.CreatedDate  = DateTime.UtcNow;
                model.ModifiedDate = DateTime.UtcNow;

                await this._repository.Add(model);

                return(this.StatusCode(StatusCodes.Status201Created, model));
            }
            catch (Exception ex)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, ex));
            }
        }
Beispiel #8
0
        public async Task <ActionResult <CPUWatercooler> > Delete(Guid Id)
        {
            try
            {
                CPUWatercooler cpuWatercooler = await this._repository.Delete(Id);

                if (cpuWatercooler == null)
                {
                    return(this.StatusCode(StatusCodes.Status404NotFound));
                }
                return(this.StatusCode(StatusCodes.Status200OK));
            }
            catch (Exception ex)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, ex));
            }
        }
        public async Task <IActionResult> Delete(Guid id, CPUWatercooler cpuWatercooler = null)
        {
            try
            {
                using (var httpClient = new HttpClient())
                {
                    using (HttpResponseMessage response = await httpClient.DeleteAsync(string.Format("{0}/{1}/{2}", this.apiBaseUrl, this.apiController, id)))
                    {
                        string apiResponse = await response.Content.ReadAsStringAsync();
                    }
                }

                return(this.RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(this.View());
            }
        }
Beispiel #10
0
        public async Task <IActionResult> Put([FromBody] CPUWatercooler model)
        {
            try
            {
                if (model != null)
                {
                    model.ModifiedDate = DateTime.UtcNow;

                    await this._repository.Update(model);

                    return(this.StatusCode(StatusCodes.Status201Created, model));
                }

                return(this.StatusCode(StatusCodes.Status204NoContent));
            }
            catch (Exception ex)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, ex));
            }
        }
        public async Task <IActionResult> Edit(Guid id, CPUWatercooler model)
        {
            try
            {
                if (model == null)
                {
                    return(this.NotFound());
                }

                if (model.ImageFile != null)
                {
                    model.ImageTitle = model.ImageFile.FileName;
                    model.ImageData  = ImageManager.GetByteArrayFromImage(model.ImageFile);
                }

                using (var httpClient = new HttpClient())
                {
                    model.CPUWatercoolerId = id;
                    string json        = JsonConvert.SerializeObject(model, Formatting.Indented);
                    var    httpContent = new StringContent(json, Encoding.UTF8, "application/json");

                    using (HttpResponseMessage response = await httpClient.PutAsync(string.Format("{0}/{1}", this.apiBaseUrl, this.apiController), httpContent))
                    {
                        string apiResponse = await response.Content.ReadAsStringAsync();    // returns object, todo: change response in api to return successfull message

                        //ViewBag.Result = "Success";
                        //receivedReservation = JsonConvert.DeserializeObject<Reservation>(apiResponse);
                    }
                }

                return(this.RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(this.View());
            }
        }