Exemple #1
0
        public async Task <int> Update(PositionsUpdateRequest request)
        {
            var position = await _context.Positions.FindAsync(request.ID);

            position.Name      = request.Name;
            position.FacultyID = request.FacultyID;
            return(await _context.SaveChangesAsync());
        }
Exemple #2
0
        public async Task <IActionResult> Update([FromForm] PositionsUpdateRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var affectedResult = await _positionsService.Update(request);

            if (affectedResult == 0)
            {
                return(BadRequest());
            }
            return(Ok());
        }
        public async Task <IActionResult> Edit([FromForm] PositionsUpdateRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(View(request));
            }

            var result = await _positionApiClient.UpdatePosition(request);

            if (result)
            {
                TempData["result"] = "Update Position succsess";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Fail update position");
            return(View(request));
        }
        public async Task <bool> UpdatePosition(PositionsUpdateRequest request)
        {
            var sessions = _httpContextAccessor
                           .HttpContext
                           .Session
                           .GetString(SystemConstants.AppSettings.Token);

            var client = _httpClientFactory.CreateClient("BackendApi");

            client.BaseAddress = new Uri(_configuration[SystemConstants.AppSettings.BaseAddress]);
            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", sessions);

            var requestContent = new MultipartFormDataContent();

            requestContent.Add(new StringContent(string.IsNullOrEmpty(request.Name) ? "" : request.Name.ToString()), "name");
            requestContent.Add(new StringContent(string.IsNullOrEmpty(request.FacultyID.ToString()) ? "" : request.FacultyID.ToString()), "FacultyID");
            var response = await client.PutAsync($"/api/positions/" + request.ID, requestContent);

            return(response.IsSuccessStatusCode);
        }