first commit
This commit is contained in:
155
Complex.EndPoint/Controllers/AccountController.cs
Normal file
155
Complex.EndPoint/Controllers/AccountController.cs
Normal file
@@ -0,0 +1,155 @@
|
||||
using Complex.Application.PersonService;
|
||||
using Complex.Application.Services.Utility;
|
||||
using Complex.Application.Utility;
|
||||
using Complex.Common.Dto;
|
||||
using Complex.Domain.Entities;
|
||||
using Complex.EndPoint.Utility;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using System.IdentityModel.Tokens.Jwt;
|
||||
using System.Security.Claims;
|
||||
using System.Text;
|
||||
|
||||
namespace Complex.EndPoint.Controllers
|
||||
{
|
||||
[ApiVersion("1")]
|
||||
[Route("api/v{version:apiVersion}/[controller]")]
|
||||
//[Route("[controller]")]
|
||||
[ApiController]
|
||||
public class AccountController : Controller
|
||||
{
|
||||
private readonly IConfiguration _configuration;
|
||||
private readonly ISiteAccountlService _SiteAccountlService;
|
||||
private readonly IUserTokenService _userTokenService;
|
||||
private readonly ISendUserMessage _sendUserMessage;
|
||||
|
||||
public AccountController(IConfiguration configuration
|
||||
, ISiteAccountlService siteAccountlService, IUserTokenService userTokenRepository,
|
||||
ISendUserMessage sendUserMessage)
|
||||
{
|
||||
this._configuration = configuration;
|
||||
this._SiteAccountlService = siteAccountlService;
|
||||
this._userTokenService = userTokenRepository;
|
||||
this._sendUserMessage = sendUserMessage;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public IActionResult Post(string PhoneNumber, string SmsCode)
|
||||
{
|
||||
try
|
||||
{
|
||||
var loginResult = _SiteAccountlService.Login(PhoneNumber, SmsCode);
|
||||
if (loginResult.IsSuccess == false)
|
||||
{
|
||||
return Ok(new LoginResultDto()
|
||||
{
|
||||
IsSuccess = false,
|
||||
Message = loginResult.Message
|
||||
});
|
||||
}
|
||||
var token = CreateToken(loginResult.Person);
|
||||
|
||||
return Ok(new LoginResultDto()
|
||||
{
|
||||
IsSuccess = true,
|
||||
Data = token,
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (ex.InnerException != null)
|
||||
ex = ex.InnerException;
|
||||
return Ok(new LoginResultDto
|
||||
{
|
||||
IsSuccess = false,
|
||||
Message = ex.Message + "----" + ex.StackTrace
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[HttpPost]
|
||||
[Route("RefreshToken")]
|
||||
public IActionResult RefreshToken(string Refreshtoken)
|
||||
{
|
||||
var usertoken = _userTokenService.FindRefreshToken(Refreshtoken);
|
||||
if (usertoken == null)
|
||||
{
|
||||
return Unauthorized();
|
||||
}
|
||||
if (usertoken.RefreshTokenExp < DateTime.Now)
|
||||
{
|
||||
return Unauthorized("Token Expire");
|
||||
}
|
||||
|
||||
var token = CreateToken(usertoken.Person);
|
||||
_userTokenService.DeleteToken(Refreshtoken);
|
||||
|
||||
return Ok(token);
|
||||
}
|
||||
|
||||
|
||||
[Route("GetSmsCode")]
|
||||
[HttpGet]
|
||||
public ResultDto GetSmsCode(string PhoneNumber)
|
||||
{
|
||||
var smsCode = _SiteAccountlService.GetCode(PhoneNumber);
|
||||
//_sendUserMessage.SendPattern("z3rx7fywigv5tdb", PhoneNumber, new { code = smsCode });
|
||||
//return new ResultDto { IsSuccess = true, Message = "پیامک ارسال شد" };
|
||||
return new ResultDto { IsSuccess = true, Message = smsCode };
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
[HttpGet]
|
||||
[Route("Logout")]
|
||||
public IActionResult Logout()
|
||||
{
|
||||
var user = User.Claims.First(p => p.Type == "UserId").Value;
|
||||
_SiteAccountlService.Logout(user);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
private LoginDataDto CreateToken(Person user)
|
||||
{
|
||||
//SecurityHelper securityHelper = new SecurityHelper();
|
||||
var claims = new List<Claim>
|
||||
{
|
||||
new Claim ("UserId", user.Id.SimpleCodeString()),
|
||||
new Claim ("Name", user.FirstName.SimpleCodeString()),
|
||||
new Claim ("Family", user.LastName.SimpleCodeString()),
|
||||
};
|
||||
string key = _configuration["JWtConfig:Key"];
|
||||
var secretKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(key));
|
||||
var credentials = new SigningCredentials(secretKey, SecurityAlgorithms.HmacSha256);
|
||||
var tokenexp = DateTime.Now.AddDays(30);//.AddMinutes(int.Parse(_configuration["JWtConfig:expires"]));
|
||||
var token = new JwtSecurityToken(
|
||||
issuer: _configuration["JWtConfig:issuer"],
|
||||
audience: _configuration["JWtConfig:audience"],
|
||||
expires: tokenexp,
|
||||
notBefore: DateTime.Now,
|
||||
claims: claims,
|
||||
signingCredentials: credentials
|
||||
);
|
||||
var jwtToken = new JwtSecurityTokenHandler().WriteToken(token);
|
||||
|
||||
var refreshToken = Guid.NewGuid();
|
||||
|
||||
_userTokenService.SaveToken(new UserToken()
|
||||
{
|
||||
MobileModel = "",
|
||||
TokenExp = tokenexp,
|
||||
TokenHash = jwtToken, //securityHelper.Getsha256Hash(jwtToken),
|
||||
Person = user,
|
||||
RefreshToken = refreshToken.ToString(),//securityHelper.Getsha256Hash(refreshToken.ToString()),
|
||||
RefreshTokenExp = DateTime.Now.AddDays(60)
|
||||
});
|
||||
|
||||
return new LoginDataDto()
|
||||
{
|
||||
Token = jwtToken,
|
||||
RefreshToken = refreshToken.ToString()
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
36
Complex.EndPoint/Controllers/AppCommonController.cs
Normal file
36
Complex.EndPoint/Controllers/AppCommonController.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using Complex.Application.AppCommon;
|
||||
using Complex.Application.Complex;
|
||||
using Complex.Common.Dto;
|
||||
using Complex.Domain.Entities;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Security.Claims;
|
||||
|
||||
namespace Complex.EndPoint.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[ApiVersion("1")]
|
||||
[Route("api/v{version:apiVersion}/[controller]/[action]")]
|
||||
//[Route("[controller]/[action]")]
|
||||
[Authorize]
|
||||
public class AppCommonController : Controller
|
||||
{
|
||||
private readonly IAppCommonService _appCommonService;
|
||||
|
||||
public AppCommonController(IAppCommonService appCommonService)
|
||||
{
|
||||
_appCommonService = appCommonService;
|
||||
}
|
||||
[HttpGet]
|
||||
public ResultDto<Poster> GetPoster()
|
||||
{
|
||||
return _appCommonService.GetPoster();
|
||||
}
|
||||
//[Authorize]
|
||||
//[HttpGet]
|
||||
//public string test()
|
||||
//{
|
||||
// return "[" + User.Claims.First(c=>c.Type=="MobilePhone").Value + "]";
|
||||
//}
|
||||
}
|
||||
}
|
||||
38
Complex.EndPoint/Controllers/BasicController.cs
Normal file
38
Complex.EndPoint/Controllers/BasicController.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using Complex.Application.Basic;
|
||||
using Complex.Common.Dto;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Complex.EndPoint.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[ApiVersion("1")]
|
||||
[Route("api/v{version:apiVersion}/[controller]/[action]")]
|
||||
//[Route("[controller]/[action]")]
|
||||
[Authorize]
|
||||
public class BasicController : Controller
|
||||
{
|
||||
private readonly IBasicService _basicService;
|
||||
|
||||
public BasicController(IBasicService basicService)
|
||||
{
|
||||
_basicService = basicService;
|
||||
}
|
||||
[HttpPost]
|
||||
[ProducesResponseType(typeof(ResultDto<List<UnitStateDto>>), StatusCodes.Status200OK)]
|
||||
public ResultDto<List<UnitStateDto>> UnitStateList(Guid ComplexId)
|
||||
{
|
||||
return _basicService.UnitStateList(ComplexId);
|
||||
}
|
||||
[HttpPost]
|
||||
public ResultDto<int> InsertUnitState(UnitStateDto unitState)
|
||||
{
|
||||
return _basicService.InsertUnitState(unitState);
|
||||
}
|
||||
[HttpPost]
|
||||
public ResultDto<bool> EditUnitState(UnitStateDto unitState)
|
||||
{
|
||||
return _basicService.EditUnitState(unitState);
|
||||
}
|
||||
}
|
||||
}
|
||||
54
Complex.EndPoint/Controllers/ComplexController.cs
Normal file
54
Complex.EndPoint/Controllers/ComplexController.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using AutoMapper;
|
||||
using Complex.Application.Complex;
|
||||
using Complex.Application.Utility;
|
||||
using Complex.Common.Dto;
|
||||
using Complex.EndPoint.Utility;
|
||||
using Complex.EndPoint.ViewModel;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Complex.EndPoint.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[ApiVersion("1")]
|
||||
[Route("api/v{version:apiVersion}/[controller]/[action]")]
|
||||
//[Route("[controller]/[action]")]
|
||||
[Authorize]
|
||||
public class ComplexController : Controller
|
||||
{
|
||||
private readonly IComplexService _complexService;
|
||||
private IMapper _mapper;
|
||||
|
||||
public ComplexController(IComplexService complexService, IMapper mapper)
|
||||
{
|
||||
_complexService = complexService;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
//[HttpPost]
|
||||
//public ResultDto<int> InsertComplex(ComplexViewModel complexVm)
|
||||
//{
|
||||
// return _complexService.InsertComplex(_mapper.Map<ComplexDto>(complexVm));
|
||||
//}
|
||||
|
||||
[HttpPost]
|
||||
public ResultDto<ComplexDto> EditComplex(ComplexViewModel complexVm)
|
||||
{
|
||||
return _complexService.EditComplex(User.GetUserId(),_mapper.Map<ComplexDto>(complexVm));
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public ResultDto<ComplexDto> ComplexProperties(Guid Id)
|
||||
{
|
||||
var complexdto = _complexService.ComplexProperties(Id);
|
||||
return complexdto;
|
||||
}
|
||||
[HttpGet]
|
||||
public ResultDto<List<ComplexDto>> ComplexList()
|
||||
{
|
||||
var MobileNumber = User.GetUserId();
|
||||
return _complexService.ComplexList(MobileNumber);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
80
Complex.EndPoint/Controllers/ManageCostController.cs
Normal file
80
Complex.EndPoint/Controllers/ManageCostController.cs
Normal file
@@ -0,0 +1,80 @@
|
||||
using Complex.Application.Services.Basic;
|
||||
//using Complex.Application.Services.Transaction;
|
||||
using Complex.Common.Dto;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Complex.EndPoint.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// مدیریت شارژ
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[ApiVersion("1")]
|
||||
[Route("api/v{version:apiVersion}/[controller]/[action]")]
|
||||
//[Route("[controller]/[action]")]
|
||||
[Authorize]
|
||||
public class ManageCostController : Controller
|
||||
{
|
||||
private ILogger _logger;
|
||||
private CostService _costCycleService;
|
||||
public ManageCostController(CostService costCycleService, ILogger<ManageCostController> logger)
|
||||
{
|
||||
_costCycleService = costCycleService;
|
||||
_logger = logger;
|
||||
}
|
||||
[HttpPost]
|
||||
public ResultDto<Guid> InsertCostCycle(CostCycleDto costCycleDto)
|
||||
{
|
||||
return _costCycleService.InsertCostCycle(costCycleDto);
|
||||
}
|
||||
[HttpPost]
|
||||
public ResultDto<bool> EditCostCycle(CostCycleDto costCycleDto)
|
||||
{
|
||||
return _costCycleService.EditCostCycle(costCycleDto);
|
||||
}
|
||||
/// <summary>
|
||||
/// لیست مدیریت شارژ یا هر گونه مخارج گرفته می شود
|
||||
/// </summary>
|
||||
/// <param name="ComplexId"></param>
|
||||
/// <param name="StartDate"></param>
|
||||
/// <param name="EndDate"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public ResultDto<List<CostCycleDto>> CostCyclsList([FromForm] Guid ComplexId, [FromForm] DateTime? StartDate = null, [FromForm] DateTime? EndDate = null)
|
||||
{
|
||||
return _costCycleService.CostCyclsList(ComplexId,
|
||||
!StartDate.HasValue ? null : DateOnly.FromDateTime(StartDate.Value),
|
||||
!EndDate.HasValue ? null : DateOnly.FromDateTime(EndDate.Value));
|
||||
}
|
||||
/// <summary>
|
||||
/// بدهی یک واحد
|
||||
/// </summary>
|
||||
/// <param name="unitId"></param>
|
||||
/// <param name="incomeCostTitleId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public ResultDto<CostOfUnitInfoDto> CalculateCostForUnit(Guid unitId, int? incomeCostTitleId)
|
||||
{
|
||||
return _costCycleService.CalculateCostForUnit(unitId, incomeCostTitleId);
|
||||
}
|
||||
/// <summary>
|
||||
/// لیست بدهی های یک واحد
|
||||
/// </summary>
|
||||
[HttpPost]
|
||||
public ResultDto<List<CostOfUnitInfoDto>> CalculateAllCostForUnit(List<Guid> unitIds)
|
||||
{
|
||||
return _costCycleService.CalculateAllCostForUnits(unitIds);
|
||||
}
|
||||
/// <summary>
|
||||
/// تاریخچه پرداختی ها و باقیمانده از آن
|
||||
/// </summary>
|
||||
[HttpPost]
|
||||
public ResultDto<List<CostOfUnitInfoDto>> CostsForUnit(List<Guid> unitIds, int? incomeCostTitleId,
|
||||
DateTime startDate, DateTime endDate)
|
||||
{
|
||||
return _costCycleService.CostsForUnits(unitIds, incomeCostTitleId,
|
||||
DateOnly.FromDateTime(startDate), DateOnly.FromDateTime(endDate));
|
||||
}
|
||||
}
|
||||
}
|
||||
41
Complex.EndPoint/Controllers/PersonController.cs
Normal file
41
Complex.EndPoint/Controllers/PersonController.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using Complex.Application.AppCommon;
|
||||
using Complex.Application.Complex;
|
||||
using Complex.Application.PersonService;
|
||||
using Complex.Common.Dto;
|
||||
using Complex.Domain.Entities;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Complex.EndPoint.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[ApiVersion("1")]
|
||||
[Route("api/v{version:apiVersion}/[controller]/[action]")]
|
||||
//[Route("[controller]/[action]")]
|
||||
[Authorize]
|
||||
public class PersonController : Controller
|
||||
{
|
||||
private readonly IPersonService _personService;
|
||||
|
||||
public PersonController(IPersonService personService)
|
||||
{
|
||||
_personService = personService;
|
||||
}
|
||||
[HttpPost]
|
||||
public ResultDto<string> InsertPerson(PersonDto person)
|
||||
{
|
||||
return _personService.InsertPerson(person);
|
||||
}
|
||||
[HttpPost]
|
||||
public ResultDto<bool> EditPerson(PersonDto person)
|
||||
{
|
||||
return _personService.EditPerson(person);
|
||||
}
|
||||
[HttpPost]
|
||||
public ResultDto<List<PersonDto>> GetAllPersons(PersonDto personSearchObj)
|
||||
{
|
||||
var persons = _personService.GetAllPersons(personSearchObj);
|
||||
return persons;
|
||||
}
|
||||
}
|
||||
}
|
||||
88
Complex.EndPoint/Controllers/UnitController.cs
Normal file
88
Complex.EndPoint/Controllers/UnitController.cs
Normal file
@@ -0,0 +1,88 @@
|
||||
using AutoMapper;
|
||||
using Complex.Application.AppCommon;
|
||||
using Complex.Application.Complex;
|
||||
using Complex.Common.Dto;
|
||||
using Complex.Domain.Entities;
|
||||
using Complex.EndPoint.Utility;
|
||||
using Complex.EndPoint.ViewModel;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Complex.EndPoint.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[ApiVersion("1")]
|
||||
[Route("api/v{version:apiVersion}/[controller]/[action]")]
|
||||
//[Route("[controller]/[action]")]
|
||||
[Authorize]
|
||||
public class UnitController : Controller
|
||||
{
|
||||
private readonly IUnitService _unitService;
|
||||
private IMapper _mapper;
|
||||
|
||||
public UnitController(IUnitService unitService, IMapper mapper)
|
||||
{
|
||||
_unitService = unitService;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ResultDto<Guid> InsertUnit(UnitViewModel unit)
|
||||
{
|
||||
//var unitDto = new UnitDto
|
||||
//{
|
||||
// AreaMeter = unit.AreaMeter,
|
||||
// ComplexId = unit.ComplexId,
|
||||
// EmergencyTels = unit.EmergencyTels,
|
||||
// Floor = unit.Floor,
|
||||
// IsActive = unit.IsActive == true,
|
||||
// LastPaymentDate = unit.LastPaymentDate,
|
||||
// ManagerDescription = unit.ManagerDescription,
|
||||
// ParkingAreaMeter = unit.ParkingAreaMeter,
|
||||
// RemainingAmount = unit.RemainingAmount,
|
||||
// OwnerId = unit.OwnerId,
|
||||
// StateId = unit.StateId,
|
||||
// YardMeter = unit.YardMeter,
|
||||
// UnitId = unit.UnitId,
|
||||
// TenantId = unit.TenantId,
|
||||
//};
|
||||
var unitDto = _mapper.Map<UnitDto>(unit);
|
||||
return _unitService.InsertUnit(User.GetUserId(),unitDto);
|
||||
}
|
||||
/// <summary>
|
||||
/// ویرایش توسط مدیر ساختمان
|
||||
/// </summary>
|
||||
/// <param name="unitDto"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public ResultDto<bool> AdminEditUnit(UnitDto unitDto)
|
||||
{
|
||||
return _unitService.AdminEditUnit(User.GetUserId(), unitDto);
|
||||
}
|
||||
/// <summary>
|
||||
/// ویرایش توسط مالک
|
||||
/// </summary>
|
||||
/// <param name="unitDto"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public ResultDto<bool> OwnerEditUnit(UnitDto unitDto)
|
||||
{
|
||||
return _unitService.OwnerEditUnit(User.GetUserId(), unitDto);
|
||||
}
|
||||
/// <summary>
|
||||
/// ویرایش توسط مستاجر
|
||||
/// </summary>
|
||||
/// <param name="unitDto"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public ResultDto<bool> TenantEditUnit(UnitDto unitDto)
|
||||
{
|
||||
return _unitService.TenantEditUnit(User.GetUserId(), unitDto);
|
||||
}
|
||||
[HttpPost]
|
||||
public ResultDto<List<UnitDto>> UnitList(UnitRequestList unitRequest)
|
||||
{
|
||||
return _unitService.UnitList(User.GetUserId(), unitRequest);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user