Skip to content

Commit

Permalink
bug fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
Oktawian-L committed Nov 3, 2019
1 parent a554998 commit c50d1ad
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
22 changes: 14 additions & 8 deletions SubitonAPI/SubitonAPI/Controllers/UsersController.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -60,31 +62,35 @@ public async Task<ActionResult<User>> 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<IActionResult> UpdateUser(int id, UserUpdateDTO user)
public async Task<IActionResult> 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();
}
else
{
throw;
}
}*/
}

return NoContent();
}
Expand Down
1 change: 0 additions & 1 deletion SubitonAPI/SubitonAPI/DTO/UserUpdateDTO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ namespace SubitonAPI.DTO
/// </summary>
public class UserUpdateDTO
{
public int Id { get; set; }
public AnimalType AnimalType { get; set; }
public string Name { get; set; }
public int Age { get; set; }
Expand Down
Binary file modified SubitonAPI/SubitonAPI/Subiton.db
Binary file not shown.

0 comments on commit c50d1ad

Please sign in to comment.