From c50d1ad47706169c69ad38d04c4c0e94c24ced80 Mon Sep 17 00:00:00 2001 From: Oktawian-L Date: Sun, 3 Nov 2019 15:27:45 +0100 Subject: [PATCH] bug fixing --- .../SubitonAPI/Controllers/UsersController.cs | 22 +++++++++++------- SubitonAPI/SubitonAPI/DTO/UserUpdateDTO.cs | 1 - SubitonAPI/SubitonAPI/Subiton.db | Bin 114688 -> 114688 bytes 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/SubitonAPI/SubitonAPI/Controllers/UsersController.cs b/SubitonAPI/SubitonAPI/Controllers/UsersController.cs index 4fedc72..503765a 100644 --- a/SubitonAPI/SubitonAPI/Controllers/UsersController.cs +++ b/SubitonAPI/SubitonAPI/Controllers/UsersController.cs @@ -1,8 +1,10 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Security.Claims; using System.Threading.Tasks; using AutoMapper; using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; using SubitonAPI.Data; using SubitonAPI.DTO; using SubitonAPI.Models; @@ -60,23 +62,27 @@ public async Task> GetUser(int id) // To protect from overposting attacks, please enable the specific properties you want to bind to, for // more details see https://aka.ms/RazorPagesCRUD. [HttpPut("{id}")] - public async Task UpdateUser(int id, UserUpdateDTO user) + public async Task PutUser(int id, UserUpdateDTO userUpdate) { - if (id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) + /* if (id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return Unauthorized(); - } + }*/ var userFromRepo = await _userRepository.GetUser(id); - /*_userRepository.Entry(user).State = EntityState.Modified; + _mapper.Map(userUpdate, userFromRepo); try { - await _userRepository.SaveChangesAsync(); + var result = await _userRepository.SaveAll(); + if (result) + return NoContent(); + else + throw new Exception($"Canot save a user data"); } catch (DbUpdateConcurrencyException) { - if (!UserExists(id)) + if (_userRepository.GetUser(id) == null) { return NotFound(); } @@ -84,7 +90,7 @@ public async Task UpdateUser(int id, UserUpdateDTO user) { throw; } - }*/ + } return NoContent(); } diff --git a/SubitonAPI/SubitonAPI/DTO/UserUpdateDTO.cs b/SubitonAPI/SubitonAPI/DTO/UserUpdateDTO.cs index 12a699e..c3b65c1 100644 --- a/SubitonAPI/SubitonAPI/DTO/UserUpdateDTO.cs +++ b/SubitonAPI/SubitonAPI/DTO/UserUpdateDTO.cs @@ -12,7 +12,6 @@ namespace SubitonAPI.DTO /// public class UserUpdateDTO { - public int Id { get; set; } public AnimalType AnimalType { get; set; } public string Name { get; set; } public int Age { get; set; } diff --git a/SubitonAPI/SubitonAPI/Subiton.db b/SubitonAPI/SubitonAPI/Subiton.db index 571cb132ed15d472f865562fcc6d034dd759d1e8..149213ac62cab9c7fae32fb8c98699f5320f1b58 100644 GIT binary patch delta 98 zcmZo@U~gz(-@v+omG2@0-^GoM8`#)5Js21`T{a)sCdeV%q{Ab{pxnsQ#KXW~Y|OyG yAj%-j0HlEw2gBsM+fGlPxQJ0?`i8}fLhMDQDV2ss#vl=4_PosGR1;IPrUL*kJ{!0I delta 294 zcmY*Uy-LJD5H`gnC)ga=*vRxk-oZlfzy}bnS~CL?|S&S6!i% zuVm>)iEzd6F?{p=Oy5_1Uk$TiR_>3={rl5UmdDr6mnY}jkKJPa=wdPu4bc+TaHB>Z z$bnI3bWeh0903&?^h(LMPBBb)1kM8tNkD2iG+6 XNP%qBpl&|r#l>zYR@HX(_4@q-yHjl*