Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace MonitoringSystem.Hubs.Controllers
- {
- using System.Linq;
- using Microsoft.AspNetCore.Authorization;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.EntityFrameworkCore;
- using AutoMapper;
- using Swashbuckle.AspNetCore.SwaggerGen;
- using MonitoringSystem.DataLayer.EFCore.Contracts;
- using MonitoringSystem.DataModels;
- using MonitoringSystem.Hubs.Dtos;
- using System.Collections.Generic;
- [Authorize]
- public class AccountController : ApiControllerBase
- {
- private readonly IUserRepository _userRepository;
- private readonly IMapper _mapper;
- public AccountController(
- IUserRepository userRepository,
- IMapper mapper)
- {
- this._userRepository = userRepository;
- this._mapper = mapper;
- }
- [HttpGet]
- [Route("/margins")]
- [ApiExplorerSettings(GroupName = "v1")]
- [SwaggerOperation("GetLoggedUserMarketMargins")]
- [SwaggerResponse(200, type: typeof(JsonResult))]
- [SwaggerResponse(400, type: typeof(IActionResult))]
- [SwaggerResponse(statusCode: 500, type: typeof(IActionResult), description: "frfrfr")]
- public IActionResult GetMarketMargins()
- {
- if (int.TryParse(User.Identity.Name, out var userIdFromToken))
- {
- using (_userRepository)
- {
- var userMarketMargins = _userRepository.GetMarketMargins(
- userIdFromToken,
- mm => mm.Include(x => x.User)
- .Include(x => x.OddType))
- .ToArray();
- return Ok(userMarketMargins);
- }
- }
- return Unauthorized();
- }
- [HttpPost]
- [Route("/margins")]
- [ApiExplorerSettings(GroupName = "v1")]
- [SwaggerOperation("GetLoggedUserMarketMargins")]
- [SwaggerResponse(200, type: typeof(JsonResult))]
- [SwaggerResponse(400, type: typeof(IActionResult))]
- [SwaggerResponse(statusCode: 500, type: typeof(IActionResult), description: "frfrfr")]
- public IActionResult SaveMarketMargins([FromBody] IEnumerable<UserMarketMarginsDto> userMarketMarginsDto)
- {
- if (userMarketMarginsDto == null)
- {
- return BadRequest("Market Margins must be provided in order to save!");
- }
- if (int.TryParse(User.Identity.Name, out var userIdFromToken))
- {
- var userMarketMargins = _mapper.Map<IEnumerable<UserMarketMargins>>(userMarketMarginsDto)
- .Select(umm =>
- {
- umm.UserID = userIdFromToken;
- return umm;
- });
- using (_userRepository)
- {
- _userRepository.SaveMarketMargin(userIdFromToken, userMarketMargins);
- return Ok(userMarketMargins);
- }
- }
- return Unauthorized();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement