first commit
This commit is contained in:
21
Complex.Application/Services/Basic/AppCommonService.cs
Normal file
21
Complex.Application/Services/Basic/AppCommonService.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using Complex.Common.Dto;
|
||||
using Complex.Domain.Entities;
|
||||
|
||||
namespace Complex.Application.AppCommon
|
||||
{
|
||||
public interface IAppCommonService
|
||||
{
|
||||
ResultDto<Poster> GetPoster();
|
||||
}
|
||||
public class AppCommonService : IAppCommonService
|
||||
{
|
||||
public ResultDto<Poster> GetPoster()
|
||||
{
|
||||
return new ResultDto<Poster>
|
||||
{
|
||||
Data = new Poster { ImagePath = "banner.png" },
|
||||
IsSuccess = true
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
71
Complex.Application/Services/Basic/BasicService.cs
Normal file
71
Complex.Application/Services/Basic/BasicService.cs
Normal file
@@ -0,0 +1,71 @@
|
||||
using AutoMapper;
|
||||
using Complex.Common.Dto;
|
||||
using Complex.Domain.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Complex.Application.Basic
|
||||
{
|
||||
public interface IBasicService
|
||||
{
|
||||
ResultDto<List<UnitStateDto>> UnitStateList(Guid ComplexId);
|
||||
ResultDto<int> InsertUnitState(UnitStateDto unitState);
|
||||
ResultDto<bool> EditUnitState(UnitStateDto unitState);
|
||||
}
|
||||
public class BasicService : IBasicService
|
||||
{
|
||||
private readonly IComplexDBContext _complexDBContext;
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
public BasicService(IComplexDBContext complexDBContext, IMapper mapper)
|
||||
{
|
||||
_complexDBContext = complexDBContext;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
public ResultDto<List<UnitStateDto>> UnitStateList(Guid ComplexId)
|
||||
{
|
||||
var UnitStates = _complexDBContext.UnitStates.Where(s => s.ComplexId == ComplexId || !s.ComplexId.HasValue).ToList()
|
||||
.Select(u=>_mapper.Map<UnitStateDto>(u)).ToList();
|
||||
return new ResultDto<List<UnitStateDto>>
|
||||
{
|
||||
Data = UnitStates,
|
||||
IsSuccess = true,
|
||||
RowCount = UnitStates.Count
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
public ResultDto<bool> EditUnitState(UnitStateDto unitStateDto)
|
||||
{
|
||||
var unitState = _complexDBContext.UnitStates.FirstOrDefault(us => us.Id == unitStateDto.Id);
|
||||
unitState.Title = unitStateDto.Title;
|
||||
unitState.Icon= unitStateDto.Icon;
|
||||
_complexDBContext.SaveChanges();
|
||||
return new ResultDto<bool> { IsSuccess = true, Message="ویرایش با موفقیت انجام شد"};
|
||||
}
|
||||
|
||||
public ResultDto<int> InsertUnitState(UnitStateDto unitStateDto)
|
||||
{
|
||||
var newUnitState = new UnitState();
|
||||
newUnitState.Title= unitStateDto.Title;
|
||||
newUnitState.Icon= unitStateDto.Icon;
|
||||
newUnitState.ComplexId= unitStateDto.ComplexId;
|
||||
_complexDBContext.UnitStates.Add(newUnitState);
|
||||
_complexDBContext.SaveChanges();
|
||||
|
||||
return new ResultDto<int> { IsSuccess = true, Data= newUnitState.Id, Message = "ثبت با موفقیت انجام شد" };
|
||||
}
|
||||
}
|
||||
public class UnitStateDto
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public Guid? ComplexId { set; get; }
|
||||
public string Title { set; get; }
|
||||
public string Icon { set; get; }
|
||||
}
|
||||
|
||||
}
|
||||
414
Complex.Application/Services/Basic/ChargeCycleService.cs
Normal file
414
Complex.Application/Services/Basic/ChargeCycleService.cs
Normal file
@@ -0,0 +1,414 @@
|
||||
using AutoMapper;
|
||||
using Complex.Application.Complex;
|
||||
using Complex.Application.Utility;
|
||||
using Complex.Common.Dto;
|
||||
using Complex.Domain.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Complex.Application.Services.Basic
|
||||
{
|
||||
public class CostService
|
||||
{
|
||||
private readonly IComplexDBContext _complexDBContext;
|
||||
private IMapper _mapper;
|
||||
private ILogger _logger;
|
||||
public CostService(IComplexDBContext complexDBContext, IMapper mapper, ILogger<CostService> logger)
|
||||
{
|
||||
_complexDBContext = complexDBContext;
|
||||
_mapper = mapper;
|
||||
_logger = logger;
|
||||
}
|
||||
//public ResultDto<List<ChargeCycleDto>> ComplexChargeCycle(Guid ComplexId)
|
||||
//{
|
||||
// var chargeCycles = _complexDBContext.ChargeCycles.Include(c => c.UnitChargeTypes).ThenInclude(c => c.Unit)
|
||||
// .Where(c => c.ComplexId == ComplexId).ToList();
|
||||
|
||||
// var chargeCycleObj = chargeCycles.Select(c => _mapper.Map<ChargeCycleDto>(c)).ToList();
|
||||
// foreach (var c in chargeCycleObj)
|
||||
// {
|
||||
// c.Units = chargeCycles.Single(a => a.Id == c.Id).UnitChargeTypes.Where(t => !t.ChargeTypeId.HasValue)
|
||||
// .Select(a => a.Unit).Select(u => _mapper.Map<UnitDto>(u)).ToList();
|
||||
// }
|
||||
// return new ResultDto<List<ChargeCycleDto>>
|
||||
// {
|
||||
// Data = chargeCycleObj,
|
||||
// IsSuccess = true,
|
||||
// };
|
||||
//}
|
||||
|
||||
/// <summary>
|
||||
/// لیست مدیریت شارژ یا هر گونه درآمد و مخارج گرفته می شود
|
||||
/// </summary>
|
||||
/// <param name="ComplexId"></param>
|
||||
/// <param name="StartDate"></param>
|
||||
/// <param name="EndDate"></param>
|
||||
/// <param name="IncomeCostTitleId"></param>
|
||||
/// <returns></returns>
|
||||
public ResultDto<List<CostCycleDto>> CostCyclsList(Guid ComplexId, DateOnly? StartDate = null,
|
||||
DateOnly? EndDate = null, int? IncomeCostTitleId = null)
|
||||
{
|
||||
if (IncomeCostTitleId.HasValue && StartDate.HasValue)
|
||||
StartDate = GetStartOfMonth(StartDate.Value);
|
||||
|
||||
var ChargeCycleQuery = _complexDBContext.CostCycles.Include(c => c.Units).Where(c => c.ComplexId == ComplexId).AsQueryable();
|
||||
if (StartDate.HasValue)
|
||||
ChargeCycleQuery = ChargeCycleQuery.Where(c => c.StartDate >= StartDate);
|
||||
|
||||
if (EndDate.HasValue)
|
||||
ChargeCycleQuery = ChargeCycleQuery.Where(c => c.EndDate <= EndDate);
|
||||
|
||||
|
||||
if (IncomeCostTitleId.HasValue)
|
||||
ChargeCycleQuery = ChargeCycleQuery.Where(c => c.IncomeCostTitleId == IncomeCostTitleId);
|
||||
else/*مدیریت شارژ ها فقط*/
|
||||
ChargeCycleQuery = ChargeCycleQuery.Where(c => c.IncomeCostTitleId == null);
|
||||
|
||||
var ChargeCycleList = ChargeCycleQuery.ToList().Select(c => new CostCycleDto
|
||||
{
|
||||
ComplexId = c.ComplexId,
|
||||
Amount = c.Amount,
|
||||
EncouragementAmount = c.EncouragementAmount,
|
||||
EncouragementDay = c.EncouragementDay,
|
||||
EndDate = c.EndDate,
|
||||
StartDate = c.StartDate,
|
||||
Id = c.Id,
|
||||
Title = c.Title,
|
||||
UnitIds = c.Units?.Select(u => u.Id).ToList(),
|
||||
UnitNames = c.Units?.Select(u => u.Id + "#" + u.UnitName).ToList(),
|
||||
IncomeCostTitleId = c.IncomeCostTitleId,
|
||||
IncomeCostTitle = c.IncomeCostTitle?.Title
|
||||
}).ToList();
|
||||
return new ResultDto<List<CostCycleDto>>
|
||||
{
|
||||
IsSuccess = true,
|
||||
RowCount = ChargeCycleList.Count,
|
||||
Data = ChargeCycleList
|
||||
};
|
||||
}
|
||||
|
||||
public ResultDto<bool> EditCostCycle(CostCycleDto costCycleDto)
|
||||
{
|
||||
var cycle = _complexDBContext.CostCycles.Single(a => a.Id == costCycleDto.Id);
|
||||
var isUsed = _complexDBContext.Transactions.Any(c => c.CostCycleId == costCycleDto.Id);
|
||||
if (isUsed)
|
||||
return new ResultDto<bool>
|
||||
{
|
||||
IsSuccess = false,
|
||||
Message = "این آیتم استفاده شده است. شما می توانید این آیتم را حذف نمایید",
|
||||
Data = false
|
||||
};
|
||||
|
||||
cycle = _mapper.Map<CostCycle>(costCycleDto);
|
||||
cycle.IncomeCostTitleId = costCycleDto.IncomeCostTitleId;
|
||||
if (costCycleDto.UnitIds != null)
|
||||
cycle.Units = _complexDBContext.Units.Where(u => costCycleDto.UnitIds.Contains(u.Id)
|
||||
&& u.ComplexId == costCycleDto.ComplexId).ToList();
|
||||
|
||||
foreach (var u in cycle.Units)
|
||||
{
|
||||
var define = DefineUnitCharge(unitId: u.Id, costCycle: cycle);
|
||||
if (!define.IsSuccess)
|
||||
return new ResultDto<bool> { Data = false, IsSuccess = true, Message = define.Message };
|
||||
}
|
||||
|
||||
_complexDBContext.SaveChanges();
|
||||
|
||||
return new ResultDto<bool> { Data = true, IsSuccess = true, Message = "ویرایش با موفقیت انجام شد" };
|
||||
}
|
||||
|
||||
private DateOnly GetStartOfMonth(DateOnly date)
|
||||
{
|
||||
var persianDate = PersianDate.GetPDate(date.ToDateTime(new TimeOnly(1, 1)));
|
||||
return date.AddDays(-persianDate.Day + 1);
|
||||
}
|
||||
|
||||
public ResultDto<Guid> InsertCostCycle(CostCycleDto costCycleDto)
|
||||
{
|
||||
//اگر مدیریت شارژ هست پس تاریخ ها باید از یکم تا پایان ماه بشود
|
||||
//البته باید در نرم افزار فقط امکان انتخاب ماه را داشته باشد
|
||||
//&^*&^*&^&*^*&^*&^&*^*&^*&^&*^*&^*&^*&^&*^&*^*&&^*&^*&^&*^*^*&^*&^*&^&*^*&
|
||||
//
|
||||
if (costCycleDto.IncomeCostTitleId == null)
|
||||
costCycleDto.StartDate = GetStartOfMonth(costCycleDto.StartDate);
|
||||
|
||||
var newCycle = _mapper.Map<CostCycle>(costCycleDto);
|
||||
if (costCycleDto.UnitIds != null)
|
||||
newCycle.Units = _complexDBContext.Units.Where(u => costCycleDto.UnitIds.Contains(u.Id) && costCycleDto.ComplexId == u.ComplexId).ToList();
|
||||
|
||||
//if(newCycle.Units==null)
|
||||
//{
|
||||
// //باید چک کرد در این بازه ایا با یکی دیگر که همه واحدها را در نظر میگیرد هم پوشانی نداشته باشد
|
||||
// اما چون در پایین چک میشه پس مشکلی ندارد
|
||||
// var IsPublicCostExist=_complexDBContext.CostCycles.Where(c=>
|
||||
// c.ComplexId== newCycle.ComplexId && )
|
||||
//}
|
||||
_complexDBContext.CostCycles.Add(newCycle);
|
||||
|
||||
foreach (var u in newCycle.Units)
|
||||
{
|
||||
var define = DefineUnitCharge(unitId: u.Id, costCycle: newCycle, isNew: true);
|
||||
if (!define.IsSuccess)
|
||||
return new ResultDto<Guid> { IsSuccess = false, Message = define.Message };
|
||||
}
|
||||
|
||||
_complexDBContext.SaveChanges();
|
||||
return new ResultDto<Guid> { Data = newCycle.Id, IsSuccess = true, Message = "ثبت با موفقیت انجام شد" };
|
||||
}
|
||||
|
||||
public ResultDto DefineUnitCharge(Guid unitId, CostCycle costCycle, bool isNew = false)
|
||||
{
|
||||
//var cycle = _complexDBContext.CostCycles.Where(c => c.Id == costCycleId).FirstOrDefault();
|
||||
var currentDate = DateOnly.FromDateTime(DateTime.Now);
|
||||
///ایتم هایی که برای بعد از این تاریخ هست باید حذف شوند و مجدد محاسبه شوند
|
||||
///اما ایتم هایی که هم تاریخ مدیریت شارژ و هم تاریخ امروز به بعد
|
||||
///البته در مدیریت شارژ تعریفی نباید اجازه داد تاریخ شروع از آن روز به قبل باشد
|
||||
if (!isNew)
|
||||
{
|
||||
var validDateTimeForDel = currentDate;
|
||||
//validDateTimeForDel.AddHours(-validDateTimeForDel.Hour);
|
||||
//validDateTimeForDel.AddMinutes(-validDateTimeForDel.Minute);
|
||||
//validDateTimeForDel.AddSeconds(-validDateTimeForDel.Second);
|
||||
var itemsForDelete = _complexDBContext.UnitCosts.Where(t =>
|
||||
t.CostCycleId == costCycle.Id &&
|
||||
t.UnitId == unitId && t.Date >= validDateTimeForDel && !t.TransactionId.HasValue);
|
||||
/*
|
||||
نکته: !t.TransactionId.HasValue
|
||||
.مشکل اینجاست که اگر برای اینده باشه و پرداخت کرده باشه باید یک راهکاری اندیشید چون حذف نمیشه!مشکل دارد
|
||||
*/
|
||||
_complexDBContext.UnitCosts.RemoveRange(itemsForDelete);
|
||||
}
|
||||
//اگر شارژ باشد فقط یک بار در ماه هست اما غیر از ان به هر هزینه تعریفی میتواند
|
||||
//که در ماه میتواند چندین هزینه تعریف کند
|
||||
//اگر برای شارژ باشد
|
||||
//if (!cycle.IncomeCostTitleId.HasValue)
|
||||
// deleteCharges = deleteCharges.Where(t => t.ChargeCycleId == ChargeCycleId);
|
||||
//else
|
||||
//deleteCharges = deleteCharges.Where(t => t.ChargeCycleId == cycle.Id);
|
||||
//همه ماهانه هست و روز خاصی نگرفتیم برای اصل و پرداخت نشده ها حذف شده
|
||||
//پس روز اخر ملاک هست
|
||||
if (!costCycle.IncomeCostTitleId.HasValue)
|
||||
while (currentDate <= costCycle.EndDate)
|
||||
{
|
||||
//میبیند برای این واحد ایا چیزی ثبت شده است یا خیر با دوره واحد دیگر
|
||||
//چون بالا برای دوره واحدی که به این تابع امده حذف را انجام دادیم
|
||||
var oldUnitCost = _complexDBContext.UnitCosts.Include(uc => uc.CostCycle).ThenInclude(c => c.Units)
|
||||
.Where(uc =>
|
||||
uc.UnitId == unitId &&
|
||||
uc.CostCycle.IncomeCostTitleId == null &&
|
||||
uc.Date.Month == currentDate.Month).FirstOrDefault();
|
||||
|
||||
if (oldUnitCost != null)
|
||||
{
|
||||
//cycle.Units != null====>پس این واحد هم اختصاصیش بوده*/
|
||||
//اگر این اختصاصی هست و قبلش اختصاصی هم بوده خطا بده
|
||||
if (costCycle.Units != null && oldUnitCost.CostCycle.Units != null)
|
||||
return new ResultDto
|
||||
{
|
||||
IsSuccess = false,
|
||||
Message = "برای برخی از واحدها در این بازه زمانی قبلا به صورت اختصاصی شارژ تعیین شده است"
|
||||
};
|
||||
//اگر این اختصاصی هست و قبلش غیراختصاصی بوده باید پاک بشه البته برای همین واحد است که حذف میشه
|
||||
if (costCycle.Units != null && oldUnitCost.CostCycle.Units == null)
|
||||
_complexDBContext.UnitCosts.Remove(oldUnitCost);
|
||||
|
||||
//اگر این غیر اختصاصی هست و قبلش غیر اختصاصی بوده قبلیش باید پاک بشه یا خطا بدهیم
|
||||
//اما خطا نمیدهیم چون ممکنه بازه ها متفاوت باشند ولی اشتراک داشته باشند. بهتره جای دیگه چک بشه
|
||||
//if (cycle.Units == null && oldUnitCost.CostCycle.Units == null)
|
||||
|
||||
//اگر این غیر اختصاصی هست و قبلیش اختصاصی بوده که نباید ثبت بشه
|
||||
if (costCycle.Units == null && oldUnitCost.CostCycle.Units != null)
|
||||
return new ResultDto { IsSuccess = true, Message = "نیاز به تعریف مجدد برای این واحد نبود" };
|
||||
|
||||
if (costCycle.Units == null && oldUnitCost.CostCycle.Units == null)
|
||||
return new ResultDto { IsSuccess = false, Message = "شما در یک بازه زمانی نمیتوانید بیش از یک مورد عمومی تعریف کنید" };
|
||||
|
||||
}
|
||||
//--------------
|
||||
var newUC = new UnitCost
|
||||
{
|
||||
CostCycleId = costCycle.Id,
|
||||
UnitId = unitId,
|
||||
Date = currentDate,
|
||||
TransactionId = null
|
||||
};
|
||||
currentDate = currentDate.AddMonths(1);
|
||||
_complexDBContext.UnitCosts.Add(newUC);
|
||||
}
|
||||
else
|
||||
{
|
||||
var newUC = new UnitCost
|
||||
{
|
||||
CostCycleId = costCycle.Id,
|
||||
UnitId = unitId,
|
||||
Date = currentDate,
|
||||
TransactionId = null
|
||||
};
|
||||
_complexDBContext.UnitCosts.Add(newUC);
|
||||
}
|
||||
// _complexDBContext.SaveChanges();
|
||||
return new ResultDto
|
||||
{
|
||||
Message = "ثبت با موفقیت انجام شد",
|
||||
IsSuccess = true,
|
||||
};
|
||||
}
|
||||
/// <summary>
|
||||
/// بدهی یک واحد
|
||||
/// </summary>
|
||||
/// <param name="unitId"></param>
|
||||
/// <param name="incomeCostTitleId"></param>
|
||||
/// <returns></returns>
|
||||
public ResultDto<CostOfUnitInfoDto> CalculateCostForUnit(Guid unitId, int? incomeCostTitleId)
|
||||
{
|
||||
var currentDate = DateOnly.FromDateTime(DateTime.Now);
|
||||
var unitCost = _complexDBContext.UnitCosts.Where(uc => unitId == uc.UnitId &&
|
||||
!uc.TransactionId.HasValue
|
||||
&& uc.CostCycle.IncomeCostTitleId == incomeCostTitleId && uc.Date <= currentDate);
|
||||
|
||||
var LastPaymentDate = _complexDBContext.UnitCosts.Where(uc => unitId == uc.UnitId &&
|
||||
uc.TransactionId.HasValue/*پرداخت شده000000000000*/
|
||||
&& uc.CostCycle.IncomeCostTitleId == incomeCostTitleId && uc.Date <= currentDate)
|
||||
.OrderBy(uc => uc.Date).LastOrDefault()?.Date;
|
||||
|
||||
var costTitle = "شارژ";
|
||||
if (incomeCostTitleId.HasValue)
|
||||
costTitle = _complexDBContext.IncomeCostTitles.First(i => i.Id == incomeCostTitleId).Title;
|
||||
|
||||
|
||||
return new ResultDto<CostOfUnitInfoDto>
|
||||
{
|
||||
Data = new CostOfUnitInfoDto
|
||||
{
|
||||
CostMount = unitCost.Sum(c => c.CostCycle.Amount),
|
||||
CostTitle = costTitle,
|
||||
LastPaymentDate = LastPaymentDate,
|
||||
UnitId = unitId
|
||||
},
|
||||
IsSuccess = true
|
||||
};
|
||||
}
|
||||
/// <summary>
|
||||
/// لیست بدهی های یک واحد
|
||||
/// </summary>
|
||||
/// <param name="unitId"></param>
|
||||
/// <returns></returns>
|
||||
public ResultDto<List<CostOfUnitInfoDto>> CalculateAllCostForUnits(List<Guid> unitIds)
|
||||
{
|
||||
var currentDate = DateOnly.FromDateTime(DateTime.Now);
|
||||
var unitCharges = _complexDBContext.UnitCosts.Include(uc => uc.CostCycle).ThenInclude(cc => cc.IncomeCostTitle)
|
||||
.Where(uc => unitIds.Contains(uc.UnitId) &&
|
||||
!uc.TransactionId.HasValue
|
||||
&& uc.Date <= currentDate).ToList();
|
||||
|
||||
var resultList = new List<CostOfUnitInfoDto>();
|
||||
foreach (var unitid in unitIds)
|
||||
{
|
||||
resultList.AddRange(unitCharges.Where(u => u.UnitId == unitid).Select(uc => new CostOfUnitInfoDto
|
||||
{
|
||||
CostMount = uc.CostCycle.Amount,
|
||||
CostTitle = uc.CostCycle.IncomeCostTitleId.HasValue ? uc.CostCycle.IncomeCostTitle?.Title : "شارژ",
|
||||
Date = uc.Date,
|
||||
UnitId = unitid,
|
||||
CostCount = unitCharges.Where(u => u.UnitId == unitid).Count()
|
||||
}).ToList());
|
||||
}
|
||||
return new ResultDto<List<CostOfUnitInfoDto>>
|
||||
{
|
||||
Data = resultList,
|
||||
IsSuccess = true
|
||||
};
|
||||
//{
|
||||
// Data = unitCharges.Sum(c => c.CostCycle.Amount),
|
||||
// Message = "تمام بدهی"
|
||||
//};
|
||||
}
|
||||
/// <summary>
|
||||
/// تاریخچه پرداختی ها و باقیمانده از آن
|
||||
/// </summary>
|
||||
/// <param name="unitId"></param>
|
||||
/// <param name="incomeCostTitleId"></param>
|
||||
/// <param name="startDate"></param>
|
||||
/// <param name="endDate"></param>
|
||||
/// <returns></returns>
|
||||
public ResultDto<List<CostOfUnitInfoDto>> CostsForUnits(List<Guid> unitIds, int? incomeCostTitleId,
|
||||
DateOnly startDate, DateOnly endDate)
|
||||
{
|
||||
var unitCharges = _complexDBContext.UnitCosts.Include(uc => uc.CostCycle).ThenInclude(cc => cc.IncomeCostTitle)
|
||||
.Where(uc => unitIds.Contains(uc.UnitId)
|
||||
//!uc.TransactionId.HasValue
|
||||
&& uc.Date >= startDate
|
||||
&& uc.Date <= endDate).ToList();//.GroupBy(g => g.UnitId);
|
||||
|
||||
var resultList = new List<CostOfUnitInfoDto>();
|
||||
|
||||
foreach (var uid in unitIds)
|
||||
{
|
||||
resultList.AddRange(unitCharges.Where(u => u.UnitId == uid).Select(uc => new CostOfUnitInfoDto
|
||||
{
|
||||
UnitCostId = uc.Id,
|
||||
CostMount = uc.CostCycle.Amount,
|
||||
CostTitle = uc.CostCycle.IncomeCostTitleId.HasValue ? uc.CostCycle.IncomeCostTitle?.Title : "شارژ",
|
||||
Date = uc.Date,
|
||||
UnitId = uid,
|
||||
CostCount = unitCharges.Where(u => u.UnitId == uid).Count()
|
||||
}).ToList());
|
||||
}
|
||||
|
||||
return new ResultDto<List<CostOfUnitInfoDto>>
|
||||
{
|
||||
Data = resultList,
|
||||
IsSuccess = true
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
public class CostOfUnitInfoDto
|
||||
{
|
||||
public long UnitCostId { set; get; }
|
||||
public Guid UnitId { get; set; }
|
||||
public int CostCount { get; set; }
|
||||
public long CostMount { get; set; }
|
||||
//public long CostCount { set; get; }
|
||||
public DateOnly? LastPaymentDate { get; set; }
|
||||
public DateOnly? Date { get; set; }
|
||||
public string? CostTitle { get; set; }
|
||||
public DateOnly? PaymentDate { set; get; }
|
||||
}
|
||||
public class CostCycleDto
|
||||
{
|
||||
public Guid Id { set; get; }
|
||||
public Guid ComplexId { set; get; }
|
||||
public string Title { set; get; }
|
||||
public DateOnly StartDate { set; get; }
|
||||
public DateOnly EndDate { set; get; }
|
||||
public long Amount { set; get; } = 0;
|
||||
/// <summary>
|
||||
/// روز از ماه برای تشویقی
|
||||
/// </summary>
|
||||
public int EncouragementDay { set; get; } = 0;
|
||||
/// <summary>
|
||||
/// مبلغ اجاره با احتساب تشویقی
|
||||
/// </summary>
|
||||
public long EncouragementAmount { set; get; } = 0;
|
||||
/// <summary>
|
||||
/// اگر برای واحدهای خاصی بود
|
||||
/// </summary>
|
||||
/// <summary>
|
||||
/// اگر برای واحدهای خاصی بود
|
||||
/// </summary>
|
||||
public virtual List<Guid>? UnitIds { set; get; }
|
||||
public virtual List<string>? UnitNames { set; get; }
|
||||
/// <summary>
|
||||
/// null یعنی شارژ
|
||||
/// </summary>
|
||||
public int? IncomeCostTitleId { set; get; }
|
||||
public string? IncomeCostTitle { set; get; }
|
||||
}
|
||||
}
|
||||
118
Complex.Application/Services/Charge/ChargeCycleService.cs
Normal file
118
Complex.Application/Services/Charge/ChargeCycleService.cs
Normal file
@@ -0,0 +1,118 @@
|
||||
// در بیسیک وجود دارد
|
||||
|
||||
|
||||
//using AutoMapper;
|
||||
//using Complex.Application.Utility;
|
||||
//using Complex.Common.Dto;
|
||||
//using Complex.Domain.Commons;
|
||||
//using Complex.Domain.Entities;
|
||||
//using Microsoft.EntityFrameworkCore;
|
||||
//using System;
|
||||
//using System.Collections.Generic;
|
||||
//using System.ComponentModel.DataAnnotations;
|
||||
//using System.Linq;
|
||||
//using System.Text;
|
||||
//using System.Threading.Tasks;
|
||||
|
||||
//namespace Complex.Application.Services.Charge
|
||||
//{
|
||||
// public class ChargeCycleService
|
||||
// {
|
||||
// /*
|
||||
// * ثبت آیتم مدیریت شارژ
|
||||
// * لیست ایتم های مدیریت شارژ
|
||||
// * ویرایش
|
||||
// */
|
||||
// private readonly IComplexDBContext _complexDBContext;
|
||||
// private readonly IMapper _mapper;
|
||||
|
||||
// public ChargeCycleService(IComplexDBContext complexDBContext, IMapper mapper)
|
||||
// {
|
||||
// _complexDBContext = complexDBContext;
|
||||
// _mapper = mapper;
|
||||
// }
|
||||
// public ResultDto<Guid> InsertManageCharge(ChargeCycleDto chargeCycleDto)
|
||||
// {
|
||||
// var CCharge = new ChargeCycle
|
||||
// {
|
||||
// Amount = chargeCycleDto.Amount,
|
||||
// ComplexId = chargeCycleDto.ComplexId,
|
||||
// EncouragementAmount = chargeCycleDto.EncouragementAmount,
|
||||
// EncouragementDay = chargeCycleDto.EncouragementDay,
|
||||
// EndDate = chargeCycleDto.EndDate,
|
||||
// InsertTime = DateTime.Now,
|
||||
// StartDate = chargeCycleDto.StartDate,
|
||||
// Title = chargeCycleDto.Title,
|
||||
// };
|
||||
// if (chargeCycleDto.UnitIds != null)
|
||||
// {
|
||||
// CCharge.UnitChargeTypes = new List<UnitChargeType>();
|
||||
// chargeCycleDto.UnitIds.ForEach(g => CCharge.UnitChargeTypes.Add(new UnitChargeType
|
||||
// {
|
||||
// ComplexId = chargeCycleDto.ComplexId,
|
||||
// ChargeTypeId = null,
|
||||
// UnitId = g
|
||||
// }));
|
||||
// }
|
||||
// _complexDBContext.ChargeCycles.Add(CCharge);
|
||||
// _complexDBContext.SaveChanges();
|
||||
// return new ResultDto<Guid>
|
||||
// {
|
||||
// IsSuccess = true,
|
||||
// Data = CCharge.Id
|
||||
// };
|
||||
// }
|
||||
// public ResultDto<List<ChargeCycleDto>> ChargeCyclsList(Guid ComplexId, DateTime? StartDate = null, DateTime? EndDate = null)
|
||||
// {
|
||||
// var ChargeCycleQuery = _complexDBContext.ChargeCycles.Include(c => c.UnitChargeTypes).ThenInclude(uc => uc.Unit).Where(c => c.ComplexId == ComplexId).AsQueryable();
|
||||
// if (StartDate != null)
|
||||
// ChargeCycleQuery = ChargeCycleQuery.Where(c => c.StartDate >= StartDate);
|
||||
|
||||
// if (EndDate != null)
|
||||
// ChargeCycleQuery = ChargeCycleQuery.Where(c => c.EndDate <= EndDate);
|
||||
|
||||
// var ChargeCycleList = ChargeCycleQuery.ToList().Select(c => new ChargeCycleDto
|
||||
// {
|
||||
// ComplexId = c.ComplexId,
|
||||
// Amount = c.Amount,
|
||||
// EncouragementAmount = c.EncouragementAmount,
|
||||
// EncouragementDay = c.EncouragementDay,
|
||||
// EndDate = c.EndDate,
|
||||
// StartDate = c.StartDate,
|
||||
// Id = c.Id,
|
||||
// Title = c.Title,
|
||||
// UnitIds = c.UnitChargeTypes?.Select(u => u.UnitId).ToList(),
|
||||
// UnitNames = c.UnitChargeTypes?.Select(u => u.Unit.UnitId + "#" + u.Unit.UnitName).ToList(),
|
||||
// }).ToList();
|
||||
// return new ResultDto<List<ChargeCycleDto>>
|
||||
// {
|
||||
// IsSuccess = true,
|
||||
// RowCount= ChargeCycleList.Count,
|
||||
// Data= ChargeCycleList
|
||||
// };
|
||||
// }
|
||||
// }
|
||||
// public class ChargeCycleDto
|
||||
// {
|
||||
// public Guid Id { get; set; }
|
||||
// public Guid ComplexId { set; get; }
|
||||
// public virtual ComplexEntity Complex { set; get; }
|
||||
// public string Title { set; get; }
|
||||
// public DateTime StartDate { set; get; }
|
||||
// public DateTime EndDate { set; get; }
|
||||
// public long Amount { set; get; } = 0;
|
||||
// /// <summary>
|
||||
// /// روز از ماه برای تشویقی
|
||||
// /// </summary>
|
||||
// public int EncouragementDay { set; get; } = 0;
|
||||
// /// <summary>
|
||||
// /// مبلغ اجاره با احتساب تشویقی
|
||||
// /// </summary>
|
||||
// public long EncouragementAmount { set; get; } = 0;
|
||||
// /// <summary>
|
||||
// /// اگر برای واحدهای خاصی بود
|
||||
// /// </summary>
|
||||
// public virtual List<Guid>? UnitIds { set; get; }
|
||||
// public virtual List<string>? UnitNames { set; get; }
|
||||
// }
|
||||
//}
|
||||
119
Complex.Application/Services/Charge/ChargeService.cs
Normal file
119
Complex.Application/Services/Charge/ChargeService.cs
Normal file
@@ -0,0 +1,119 @@
|
||||
//using AutoMapper;
|
||||
//using Complex.Application.Services.Transaction;
|
||||
//using Complex.Application.Utility;
|
||||
//using Complex.Common.Dto;
|
||||
//using Complex.Domain.Entities;
|
||||
//using Microsoft.EntityFrameworkCore;
|
||||
//using System;
|
||||
//using System.Collections.Generic;
|
||||
//using System.ComponentModel.DataAnnotations;
|
||||
//using System.Linq;
|
||||
//using System.Text;
|
||||
//using System.Threading.Tasks;
|
||||
|
||||
//namespace Complex.Application.Services.Charge
|
||||
//{
|
||||
// public class CostService
|
||||
// {
|
||||
// private readonly IComplexDBContext _complexDBContext;
|
||||
// private readonly IMapper _mapper;
|
||||
|
||||
// public CostService(IComplexDBContext complexDBContext, IMapper mapper)
|
||||
// {
|
||||
// _complexDBContext = complexDBContext;
|
||||
// _mapper = mapper;
|
||||
// }
|
||||
// public ResultDto DefineUnitCharge(Guid unitId, Guid costCycleId)
|
||||
// {
|
||||
// var cycle = _complexDBContext.CostCycles.Where(c => c.Id == costCycleId).FirstOrDefault();
|
||||
// var currentDate = DateTime.Now;
|
||||
// ///ایتم هایی که برای بعد از این تاریخ هست باید حذف شوند و مجدد محاسبه شوند
|
||||
// ///اما ایتم هایی که هم تاریخ مدیریت شارژ و هم تاریخ امروز به بعد
|
||||
// ///البته در مدیریت شارژ تعریفی نباید اجازه داد تاریخ شروع از آن روز به قبل باشد
|
||||
// var itemsForDelete = _complexDBContext.UnitCosts.Where(t =>
|
||||
// t.CostCycleId == costCycleId &&
|
||||
// t.UnitId == unitId && t.Date >= currentDate && !t.TransactionId.HasValue);
|
||||
// //اگر شارژ باشد فقط یک بار در ماه هست اما غیر از ان به هر هزینه تعریفی میتواند
|
||||
// //که در ماه میتواند چندین هزینه تعریف کند
|
||||
// //اگر برای شارژ باشد
|
||||
// //if (!cycle.IncomeCostTitleId.HasValue)
|
||||
// // deleteCharges = deleteCharges.Where(t => t.ChargeCycleId == ChargeCycleId);
|
||||
// //else
|
||||
// //deleteCharges = deleteCharges.Where(t => t.ChargeCycleId == cycle.Id);
|
||||
// _complexDBContext.UnitCosts.RemoveRange(itemsForDelete);
|
||||
// //همه ماهانه هست و روز خاصی نگرفتیم برای اصل و پرداخت نشده ها حذف شده
|
||||
// //پس روز اخر ملاک هست
|
||||
// while (currentDate < cycle.EndDate)
|
||||
// {
|
||||
// var newUC = new UnitCost
|
||||
// {
|
||||
// CostCycleId = costCycleId,
|
||||
// UnitId = unitId,
|
||||
// Date = currentDate,
|
||||
// TransactionId = null
|
||||
// };
|
||||
// currentDate.AddMonths(1);
|
||||
// _complexDBContext.UnitCosts.Add(newUC);
|
||||
// }
|
||||
// _complexDBContext.SaveChanges();
|
||||
// return new ResultDto
|
||||
// {
|
||||
// Message = "ثبت با موفقیت انجام شد",
|
||||
// IsSuccess = true,
|
||||
// };
|
||||
// }
|
||||
// public /*ResultDto<List<long>>*/ void CalculateUnitCharge(Guid unitId, int? IncomeCostTitleId)
|
||||
// {
|
||||
// var currentDate = DateTime.Now;
|
||||
// var unitCharges = _complexDBContext.UnitCosts.Where(uc => uc.UnitId == unitId && !uc.TransactionId.HasValue
|
||||
// && uc.CostCycle.IncomeCostTitleId == IncomeCostTitleId);
|
||||
// }
|
||||
// //public /*ResultDto<List<long>>*/ void CalculateUnitCharge(Guid complexId, Guid unitId)
|
||||
// //{
|
||||
// // var CurrentMonth = PersianDate.CurrentPersianMonth;
|
||||
// // var CurrentYear = PersianDate.CurrentPersianYear;
|
||||
// // var currentMonthDate = PersianDate.ConvertToMiladi(CurrentYear + "/" + CurrentMonth.ToString().PadLeft(2, '0') + "/01");
|
||||
// // var manageChargList = _complexDBContext.ChargeCycles.Include(m => m.UnitChargeTypes)
|
||||
// // .Where(m => m.ComplexId == complexId
|
||||
// // && m.StartDate <= currentMonthDate
|
||||
// // && m.EndDate >= currentMonthDate).Select(m => m).ToList();
|
||||
// // ///بدست اوردن ماه هایی که شارژ نداده است
|
||||
// // var startChargeDate = _complexDBContext.ChargeCycles
|
||||
// // .Where(m => m.ComplexId == complexId)
|
||||
// // .Min(m => m.StartDate);
|
||||
// // //for(var d=startChargeDate;d<=yearMonth;d.AddDays(1))
|
||||
// // //{
|
||||
|
||||
// // //}
|
||||
// // var startPersianDate = PersianDate.GetPDate(startChargeDate);
|
||||
// // var endPersianDate = PersianDate.GetPDate(DateTime.Now);
|
||||
|
||||
// // var paymentDatelist =
|
||||
// // for (int y = startPersianDate.Year; y <= endPersianDate.Year; y++)
|
||||
// // {
|
||||
// // for (int m = startPersianDate.Month; m <= endPersianDate.Month; m++)
|
||||
// // {
|
||||
|
||||
// // }
|
||||
// // }
|
||||
// //}
|
||||
// }
|
||||
// public class ChargeDto
|
||||
// {
|
||||
// public int TransactionTitleId { get; } = 1;
|
||||
// public string TransactionTitle { get; } = "شارژ";
|
||||
// [MaxLength(10)]
|
||||
// public string TransactionDate { set; get; }
|
||||
// public long Amount { set; get; } = 0;
|
||||
// public string? Description { set; get; }
|
||||
// public int? ChargeTypeId { set; get; } = 1;
|
||||
// public string ChargeType { set; get; } = "شارژ ماهیانه";
|
||||
// public Guid? UnitId { set; get; }
|
||||
// public string UnitTitle { set; get; }
|
||||
// /// <summary>
|
||||
// ///شماره فیش. اگر با فیش چیزی واریز شده است
|
||||
// /// </summary>
|
||||
// public string? FishId { set; get; }
|
||||
// }
|
||||
|
||||
//}
|
||||
174
Complex.Application/Services/Complex/ComplexService.cs
Normal file
174
Complex.Application/Services/Complex/ComplexService.cs
Normal file
@@ -0,0 +1,174 @@
|
||||
using AutoMapper;
|
||||
using Complex.Application.Utility;
|
||||
using Complex.Common.Dto;
|
||||
using Complex.Domain.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Complex.Application.Complex
|
||||
{
|
||||
public interface IComplexService
|
||||
{
|
||||
ResultDto<int> InsertComplex(ComplexDto complexDto);
|
||||
ResultDto<ComplexDto> EditComplex(string UserId, ComplexDto complexDto);
|
||||
public ResultDto<ComplexDto> ComplexProperties(Guid Id);
|
||||
public ResultDto<List<ComplexDto>> ComplexList(string PersonId);
|
||||
}
|
||||
public class ComplexService : IComplexService
|
||||
{
|
||||
private readonly IComplexDBContext _complexDBContext;
|
||||
private IMapper _mapper;
|
||||
public ComplexService(IComplexDBContext complexDBContext, IMapper mapper)
|
||||
{
|
||||
_complexDBContext = complexDBContext;
|
||||
_mapper = mapper;
|
||||
}
|
||||
public ResultDto<ComplexDto> ComplexProperties(Guid Id)
|
||||
{
|
||||
var complex = _complexDBContext.ComplexEntities.Include(x => x.City).FirstOrDefault(x => x.Id == Id);
|
||||
if (complex == null)
|
||||
return new ResultDto<ComplexDto> { IsSuccess = false, Message = "مشخصات مجتمع یافت نشد" };
|
||||
var complexDto = _mapper.Map<ComplexDto>(complex);
|
||||
|
||||
complexDto.CityTitle = complex.City.CityTitle;
|
||||
|
||||
return new ResultDto<ComplexDto> { IsSuccess = true, RowCount = 1, Data = complexDto };
|
||||
}
|
||||
|
||||
public ResultDto<ComplexDto> EditComplex(string UserId, ComplexDto complexDto)
|
||||
{
|
||||
var complex = _complexDBContext.ComplexEntities.Include(c => c.ComplexManagers).FirstOrDefault(x => x.Id == complexDto.Id);
|
||||
|
||||
if (complex.ComplexManagers == null || !complex.ComplexManagers.Any(m => m.ManagerMobileNumberId == UserId))
|
||||
return new ResultDto<ComplexDto>
|
||||
{
|
||||
IsSuccess = false,
|
||||
Message = "عدم دسترسی"
|
||||
};
|
||||
|
||||
complex.AreaMeter = complexDto.AreaMeter;
|
||||
complex.YardMeter = complexDto.YardMeter;
|
||||
complex.Address = complexDto.Address;
|
||||
complex.YearMake = complexDto.YearMake;
|
||||
//complex.ParentId = complexDto.ParentId;
|
||||
complex.CityId = complexDto.CityId;
|
||||
complex.Description = complexDto.Description;
|
||||
complex.ElevatorCount = complexDto.ElevatorCount;
|
||||
complex.ParentId = complexDto.ParentId;
|
||||
complex.StateId = complexDto.StateId;
|
||||
complex.Title = complexDto.Title;
|
||||
complex.WarehouseCount = complexDto.WarehouseCount;
|
||||
|
||||
_complexDBContext.SaveChanges();
|
||||
|
||||
var result = _mapper.Map<ComplexDto>(complex);
|
||||
return new ResultDto<ComplexDto>
|
||||
{
|
||||
Data = result,
|
||||
IsSuccess = true,
|
||||
Message = "ویرایش با موفقیت انجام شد"
|
||||
};
|
||||
}
|
||||
|
||||
public ResultDto<int> InsertComplex(ComplexDto complexDto)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
public ResultDto<List<ComplexDto>> ComplexList(string PersonId)
|
||||
{
|
||||
//try
|
||||
{
|
||||
var today = PersianDate.GetToday();
|
||||
var mangerComplexData = _complexDBContext.ComplexManagers.Include(c => c.Complex)
|
||||
//.ThenInclude(c=>c.Units)
|
||||
//.ThenInclude(c=>c.City)
|
||||
.Where(c => (c.ManagerMobileNumberId == PersonId)
|
||||
&& string.Compare(c.StartDate, today) <= 0 && string.Compare(c.EndDate, today) >= 0)
|
||||
.Select(c => c.Complex)
|
||||
.Where(c => c.StateId != 2);//غیرفعال شده ها نیایند
|
||||
//.ToList();
|
||||
//var mangerComplex = mangerComplexData.Select(c => _mapper.Map<ComplexDto>(c)).ToList();
|
||||
|
||||
var units = _complexDBContext.Units.ToList();
|
||||
|
||||
var PersonComplexData = _complexDBContext.Units.Include(c => c.Complex)
|
||||
//.ThenInclude(c=>c.Units)
|
||||
//.ThenInclude(c => c.City)
|
||||
.Where(c => c.TenantId == PersonId || c.OwnerId == PersonId).Select(c => c.Complex)
|
||||
.Where(c => c.StateId != 2);//غیرفعال شده ها نیایند
|
||||
//.ToList();
|
||||
|
||||
var complexList = mangerComplexData.Union(PersonComplexData)
|
||||
//.Include(c => c.Units);
|
||||
.Select(c => new
|
||||
{
|
||||
complex = c,
|
||||
unitCount = c.Units.Count,
|
||||
managers = c.ComplexManagers.Select(m => m.ManagerMobileNumber).Select(p => p.FirstName + " " + p.LastName),
|
||||
cityTitle = c.City.CityTitle
|
||||
});
|
||||
//.Select(c => _mapper.Map<ComplexDto>(c));
|
||||
var result = new List<ComplexDto>();
|
||||
foreach (var item in complexList)
|
||||
{
|
||||
var complexDto = _mapper.Map<ComplexDto>(item.complex);
|
||||
complexDto.UnitCount = item.unitCount;
|
||||
complexDto.CityTitle = item.cityTitle;
|
||||
complexDto.ManagerName = String.Join(",", item.managers);
|
||||
result.Add(complexDto);
|
||||
}
|
||||
//var PersonComplex = PersonComplexData.Select(c => _mapper.Map<ComplexDto>(c));
|
||||
|
||||
return new ResultDto<List<ComplexDto>>(result);
|
||||
}
|
||||
//catch (Exception ex)
|
||||
//{
|
||||
// return new ResultDto<List<ComplexDto>>
|
||||
// {
|
||||
// Message = ex.InnerException != null ? ex.InnerException.Message + Environment.NewLine + ex.InnerException.Data :
|
||||
// ex.Message + Environment.NewLine + ex.Data,
|
||||
// IsSuccess = false
|
||||
// };
|
||||
//}
|
||||
}
|
||||
|
||||
}
|
||||
public class ComplexDto
|
||||
{
|
||||
public Guid? Id { get; set; }
|
||||
//public DateTime InsertTime { get; set; }
|
||||
//public DateTime? UpdateTime { get; set; }
|
||||
public string Title { set; get; }
|
||||
public string? Address { set; get; }
|
||||
/// <summary>
|
||||
/// وضعیت
|
||||
/// </summary>
|
||||
public int? StateId { set; get; }
|
||||
/// <summary>
|
||||
/// متراژ کل
|
||||
/// </summary>
|
||||
public int? AreaMeter { set; get; }
|
||||
/// <summary>
|
||||
/// متراژ حیاط
|
||||
/// </summary>
|
||||
public int? YardMeter { set; get; }
|
||||
/// <summary>
|
||||
/// تعداد آسانسور
|
||||
/// </summary>
|
||||
public int? ElevatorCount { set; get; }
|
||||
/// <summary> تعداد انباری</summary>
|
||||
public int? WarehouseCount { set; get; }
|
||||
public int? YearMake { set; get; }
|
||||
public int CityId { set; get; }
|
||||
public Guid? ParentId { set; get; }
|
||||
public string? Description { set; get; }
|
||||
public string? CityTitle { set; get; }
|
||||
public string? ManagerName { set; get; }
|
||||
public int UnitCount { set; get; }
|
||||
|
||||
}
|
||||
}
|
||||
92
Complex.Application/Services/PersonService/PersonService.cs
Normal file
92
Complex.Application/Services/PersonService/PersonService.cs
Normal file
@@ -0,0 +1,92 @@
|
||||
using AutoMapper;
|
||||
using Complex.Application.Utility;
|
||||
using Complex.Common.Dto;
|
||||
using Complex.Domain.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Complex.Application.PersonService
|
||||
{
|
||||
public interface IPersonService
|
||||
{
|
||||
public ResultDto<string> InsertPerson(PersonDto person);
|
||||
public ResultDto<bool> EditPerson(PersonDto person);
|
||||
public ResultDto<List<PersonDto>> GetAllPersons(PersonDto personSearchObj);
|
||||
}
|
||||
public class PersonService : IPersonService
|
||||
{
|
||||
private readonly IComplexDBContext _complexDBContext;
|
||||
private IMapper _mapper;
|
||||
public PersonService(IComplexDBContext complexDBContext, IMapper mapper)
|
||||
{
|
||||
_complexDBContext = complexDBContext;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
public ResultDto<List<PersonDto>> GetAllPersons(PersonDto personSearchObj)
|
||||
{
|
||||
var persons = _complexDBContext.ComplexPersons.Where(u => u.ComplexId == personSearchObj.ComplexId).Select(cp => cp.PersonMobileNumber);
|
||||
//در تمام فیلدها با شماره تلفن میتوان جستجو کرد
|
||||
if (personSearchObj.MobileNumber.IsNotNullOrEmpty())
|
||||
{
|
||||
persons = persons.Where(p => p.Id.Contains(personSearchObj.MobileNumber));
|
||||
persons = persons.Where(p => p.FirstName.Contains(personSearchObj.MobileNumber));
|
||||
persons = persons.Where(p => p.FirstName.Contains(personSearchObj.MobileNumber));
|
||||
}
|
||||
//if (personSearchObj.FirstName.IsNotNullOrEmpty())
|
||||
// persons = persons.Where(p => p.FirstName.Contains(personSearchObj.FirstName));
|
||||
|
||||
//if (personSearchObj.LastName.IsNotNullOrEmpty())
|
||||
// persons = persons.Where(p => p.LastName.Contains(personSearchObj.LastName));
|
||||
|
||||
//var persons = _complexDBContext.Units.Where(u => u.ComplexId == personSearchObj.ComplexId).Select(p => p.Tenant);
|
||||
//persons = persons.Union(_complexDBContext.Units.Where(u => u.ComplexId == personSearchObj.ComplexId).Select(p => p.Owner));
|
||||
|
||||
//if (personSearchObj.MobileNumber.IsNotNullOrEmpty())
|
||||
// persons = persons.Where(p => p.Id.Contains(personSearchObj.MobileNumber));
|
||||
|
||||
//var personResult = persons.Distinct().ToList();
|
||||
return new ResultDto<List<PersonDto>>
|
||||
{
|
||||
Data = persons.Select(p => _mapper.Map<PersonDto>(p)).ToList(),
|
||||
IsSuccess = true
|
||||
};
|
||||
}
|
||||
|
||||
public ResultDto<bool> EditPerson(PersonDto person)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public ResultDto<string> InsertPerson(PersonDto personDto)
|
||||
{
|
||||
var newPerson = _mapper.Map<Person>(personDto);
|
||||
var isExist = _complexDBContext.Persons.Any(p => p.Id == personDto.MobileNumber);
|
||||
if (!isExist)
|
||||
{
|
||||
newPerson.Id = personDto.MobileNumber;
|
||||
_complexDBContext.Persons.Add(newPerson);
|
||||
_complexDBContext.SaveChanges();
|
||||
}
|
||||
_complexDBContext.ComplexPersons.Add(new ComplexPerson
|
||||
{
|
||||
ComplexId = personDto.ComplexId.Value,
|
||||
PersonMobileNumberId = personDto.MobileNumber,
|
||||
});
|
||||
return new ResultDto<string> { Data = newPerson.Id, IsSuccess = true };
|
||||
}
|
||||
}
|
||||
public class PersonDto
|
||||
{
|
||||
public Guid? ComplexId { set; get; }
|
||||
public string? MobileNumber { set; get; }
|
||||
public string? FirstName { get; set; }
|
||||
public string? LastName { get; set; }
|
||||
public byte? Gender { set; get; }
|
||||
//public int? MobileCode { set; get; }
|
||||
public byte[]? Avatar { set; get; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Complex.Domain.Entities;
|
||||
namespace Complex.Application.PersonService
|
||||
{
|
||||
public interface ISiteAccountlService
|
||||
{
|
||||
Person FindUserWithPhonenumber(string phoneNumber);
|
||||
string GetCode(string PhoneNumber);
|
||||
Person GetUser(string mobileNumber);
|
||||
LoginDto Login(string phoneNumber, string Code);
|
||||
void Logout(string mobileNumber);
|
||||
Person RegisterUser(string PhoneNumber);
|
||||
}
|
||||
|
||||
public class SiteAccountlService : ISiteAccountlService
|
||||
//: IPortalService
|
||||
{
|
||||
// ==============================
|
||||
|
||||
private IComplexDBContext _complexDBContext;
|
||||
// ==============================
|
||||
|
||||
public SiteAccountlService(IComplexDBContext complexDBContext)
|
||||
{
|
||||
_complexDBContext = complexDBContext;
|
||||
}
|
||||
|
||||
// ==============================
|
||||
public Person GetUser(string mobileNumber)
|
||||
{
|
||||
var user = _complexDBContext.Persons.SingleOrDefault(p => p.Id == mobileNumber);
|
||||
return user;
|
||||
}
|
||||
|
||||
public string GetCode(string PhoneNumber)
|
||||
{
|
||||
Random random = new Random();
|
||||
string code = random.Next(1000, 9999).ToString();
|
||||
SmsCode smsCode = new SmsCode()
|
||||
{
|
||||
Code = code,
|
||||
InsertDate = DateTime.Now,
|
||||
PhoneNumber = PhoneNumber,
|
||||
RequestCount = 0,
|
||||
Used = false,
|
||||
};
|
||||
_complexDBContext.Add(smsCode);
|
||||
_complexDBContext.SaveChanges();
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
public LoginDto Login(string phoneNumber, string Code)
|
||||
{
|
||||
var user = FindUserWithPhonenumber("09192530212");
|
||||
if (user != null)
|
||||
{
|
||||
return new LoginDto
|
||||
{
|
||||
IsSuccess = true,
|
||||
Person = user,
|
||||
};
|
||||
}
|
||||
var smsCode = _complexDBContext.SmsCodes.Where(p => p.PhoneNumber == phoneNumber
|
||||
&& p.Code == Code).FirstOrDefault();
|
||||
if (smsCode == null)
|
||||
{
|
||||
return new LoginDto
|
||||
{
|
||||
IsSuccess = false,
|
||||
Message = "کد وارد شده صحیح نیست!",
|
||||
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
if (smsCode.Used == true)
|
||||
{
|
||||
return new LoginDto
|
||||
{
|
||||
IsSuccess = false,
|
||||
Message = "کد وارد شده صحیح نیست!",
|
||||
|
||||
};
|
||||
}
|
||||
////
|
||||
///
|
||||
smsCode.RequestCount++;
|
||||
|
||||
smsCode.Used = true;
|
||||
_complexDBContext.SaveChanges();
|
||||
user = FindUserWithPhonenumber(phoneNumber);
|
||||
if (user != null)
|
||||
{
|
||||
return new LoginDto
|
||||
{
|
||||
IsSuccess = true,
|
||||
Person = user,
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
user = RegisterUser(phoneNumber);
|
||||
return new LoginDto
|
||||
{
|
||||
IsSuccess = true,
|
||||
Person = user,
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Person FindUserWithPhonenumber(string phoneNumber)
|
||||
{
|
||||
var user = _complexDBContext.Persons.SingleOrDefault(p => p.Id.Equals(phoneNumber));
|
||||
return user;
|
||||
}
|
||||
|
||||
public Person RegisterUser(string PhoneNumber)
|
||||
{
|
||||
Person user = new Person()
|
||||
{
|
||||
Id = PhoneNumber,
|
||||
IsActive = true,
|
||||
};
|
||||
return user;
|
||||
}
|
||||
public void Logout(string mobileNumber)
|
||||
{
|
||||
var userToken = _complexDBContext.UserTokens.Where(p => p.PersonId/*همان موبایل*/ == mobileNumber).ToList();
|
||||
_complexDBContext.UserTokens.RemoveRange(userToken);
|
||||
_complexDBContext.SaveChanges();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class LoginDto
|
||||
{
|
||||
public bool IsSuccess { get; set; }
|
||||
public string Message { get; set; }
|
||||
public Person Person { get; set; }
|
||||
}
|
||||
public class LoginDataDto
|
||||
{
|
||||
public string Token { get; set; }
|
||||
public string RefreshToken { get; set; }
|
||||
}
|
||||
public class LoginResultDto
|
||||
{
|
||||
public bool IsSuccess { get; set; }
|
||||
public string Message { get; set; }
|
||||
public LoginDataDto Data { get; set; }
|
||||
}
|
||||
|
||||
//public class PersonDto
|
||||
//{
|
||||
// public long PersonId { get; set; }
|
||||
// public string FirstName { get; set; }
|
||||
// public string LastName { get; set; }
|
||||
// public string Mobile { get; set; }
|
||||
// public bool? IsActive { get; set; }
|
||||
//}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
using Complex.Domain.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Complex.Application.PersonService
|
||||
{
|
||||
public interface IUserTokenService
|
||||
{
|
||||
bool CheckExistToken(string Token);
|
||||
void DeleteToken(string RefreshToken);
|
||||
UserToken FindRefreshToken(string RefreshToken);
|
||||
void SaveToken(UserToken userToken);
|
||||
}
|
||||
|
||||
public class UserTokenService : IUserTokenService
|
||||
{
|
||||
|
||||
private IComplexDBContext _complexDBContext;
|
||||
public UserTokenService(IComplexDBContext complexDBContext)
|
||||
{
|
||||
_complexDBContext = complexDBContext;
|
||||
}
|
||||
|
||||
public void SaveToken(UserToken userToken)
|
||||
{
|
||||
_complexDBContext.UserTokens.Add(userToken);
|
||||
_complexDBContext.SaveChanges();
|
||||
}
|
||||
|
||||
public UserToken FindRefreshToken(string RefreshToken)
|
||||
{
|
||||
//SecurityHelper securityHelper = new SecurityHelper();
|
||||
|
||||
string RefreshTokenHash = RefreshToken;
|
||||
//string RefreshTokenHash = securityHelper.Getsha256Hash(RefreshToken);
|
||||
var usertoken = _complexDBContext.UserTokens.Include(p => p.Person)
|
||||
.SingleOrDefault(p => p.RefreshToken == RefreshTokenHash);
|
||||
return usertoken;
|
||||
}
|
||||
|
||||
public void DeleteToken(string RefreshToken)
|
||||
{
|
||||
var token = FindRefreshToken(RefreshToken);
|
||||
if (token != null)
|
||||
{
|
||||
_complexDBContext.UserTokens.Remove(token);
|
||||
_complexDBContext.SaveChanges();
|
||||
}
|
||||
}
|
||||
|
||||
public bool CheckExistToken(string Token)
|
||||
{
|
||||
//SecurityHelper securityHelper = new SecurityHelper();
|
||||
string tokenHash = Token; //securityHelper.Getsha256Hash(Token);
|
||||
var userToken = _complexDBContext.UserTokens.Where(p => p.TokenHash == tokenHash).FirstOrDefault();
|
||||
return userToken == null ? false : true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
using AutoMapper;
|
||||
using Complex.Application.Common;
|
||||
using Complex.Application.Utility;
|
||||
using Complex.Common.Dto;
|
||||
using Complex.Domain.Commons;
|
||||
using Complex.Domain.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Complex.Application.Services.TransactionServices
|
||||
{
|
||||
public interface ITransactionService
|
||||
{
|
||||
/*
|
||||
گزارش پرداختی های یک واحد
|
||||
گزارش وضعیت پرداخت واحدهای یک مجتمع
|
||||
ثبت یک تراکنش شارژ
|
||||
|
||||
*/
|
||||
}
|
||||
|
||||
public class TransactionService : ITransactionService
|
||||
{
|
||||
private readonly IComplexDBContext _complexDBContext;
|
||||
private IMapper _mapper;
|
||||
|
||||
public TransactionService(IComplexDBContext complexDBContext, IMapper mapper)
|
||||
{
|
||||
_complexDBContext = complexDBContext;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
public ResultDto<List<TransactionDto>> UnitsByTransStateList(Guid complexId, Guid? UnitId, CommonRequestDto commonRequestDto)
|
||||
{
|
||||
var trans = _complexDBContext.Transactions.Include(t => t.TransactionTitle).Include(t => t.CostCycle).Include(t => t.Person).Where(t => t.ComplexId == complexId)
|
||||
.Where(t => UnitId.HasValue ? t.UnitId == UnitId : true)
|
||||
.ToPagedByOrder(commonRequestDto, out int rowCount).ToList();
|
||||
var result = trans.Select(t => new TransactionDto
|
||||
{
|
||||
Amount = t.Amount,
|
||||
CostCycleId = t.CostCycleId,
|
||||
CostCycleTitle = t.CostCycle.Title,
|
||||
Description = t.Description,
|
||||
PersonId = t.PersonId,
|
||||
PersonName = t.Person.FirstName + " " + t.Person.LastName,
|
||||
TransactionDate = t.TransactionDate,
|
||||
TransactionPersianDate = t.TransactionPersianDate,
|
||||
TransactionTitle = t.TransactionTitle.Title,
|
||||
UnitCostDate = t.UnitCost.Date,
|
||||
UnitId = t.UnitId,
|
||||
UnitName = t.Unit.UnitName
|
||||
}).ToList();
|
||||
return new ResultDto<List<TransactionDto>>
|
||||
{
|
||||
Data = result,
|
||||
IsSuccess = true,
|
||||
};
|
||||
}
|
||||
public ResultDto PayCosts(List<long> UnitCostIds, Guid UnitId, long Amount,
|
||||
string UserPhone, string Description)
|
||||
{
|
||||
var costs = _complexDBContext.UnitCosts.Include(uc => uc.CostCycle)
|
||||
.Where(uc => UnitCostIds.Contains(uc.Id) && !uc.TransactionId.HasValue).ToList();
|
||||
var savedAmount = costs.Sum(c => c.CostCycle.Amount);
|
||||
if (savedAmount != Amount)
|
||||
return new ResultDto
|
||||
{
|
||||
IsSuccess = false,
|
||||
Message = "مبلغ صحیح نمی باشد"
|
||||
};
|
||||
|
||||
foreach (var c in costs)
|
||||
{
|
||||
var newTrans = new Transaction
|
||||
{
|
||||
PersonId = UserPhone,
|
||||
TransactionDate = DateTime.Now,
|
||||
Amount = c.CostCycle.Amount,
|
||||
CostCycleId = c.CostCycleId,
|
||||
UnitId = UnitId,
|
||||
TransactionTitleId = c.CostCycle.IncomeCostTitleId,
|
||||
ComplexId = c.CostCycle.ComplexId,
|
||||
Description = Description,
|
||||
TransactionPersianDate = PersianDate.GetDate(DateTime.Now),
|
||||
UnitCostId = c.Id
|
||||
};
|
||||
c.Transaction = newTrans;
|
||||
//_complexDBContext.Transactions.Add(newTrans);
|
||||
}
|
||||
_complexDBContext.SaveChanges();
|
||||
return new ResultDto
|
||||
{
|
||||
IsSuccess = true,
|
||||
Message = "ثبت با موفقیت انجام شد"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public class TransactionDto
|
||||
{
|
||||
public string TransactionTitle { set; get; }
|
||||
public string TransactionPersianDate { set; get; }
|
||||
public DateTime TransactionDate { set; get; }
|
||||
public long Amount { set; get; } = 0;
|
||||
public string? Description { set; get; }
|
||||
public Guid? CostCycleId { set; get; }
|
||||
public string CostCycleTitle { set; get; }
|
||||
public Guid? UnitId { set; get; }
|
||||
public string UnitName { set; get; }
|
||||
//public string? TrackingCode { set; get; }
|
||||
//public long Remaining { set; get; } = 0;
|
||||
|
||||
public DateOnly UnitCostDate { set; get; }
|
||||
public string PersonId { set; get; }
|
||||
public string PersonName { set; get; }
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
public class UnitTrancactionStateDto
|
||||
{
|
||||
public Guid UnitId { get; set; }
|
||||
public string UnitTitle { get; set; }
|
||||
/// <summary>
|
||||
/// مقدار شارژ پرداخت نشده
|
||||
/// </summary>
|
||||
public int ChargeNoPayAmount { get; set; }
|
||||
/// <summary>
|
||||
/// تعداد شارژ پرداخت نشده
|
||||
/// </summary>
|
||||
public int ChargeNoPayCount { get; set; }
|
||||
/// <summary>
|
||||
/// مقدار پرداخت نشده غیر شارژ
|
||||
/// </summary>
|
||||
public int OtherNoPayAmount { get; set; }
|
||||
/// <summary>
|
||||
/// میزان پرداخت کرده
|
||||
/// </summary>
|
||||
public long PayAmountInYear { set; get; }
|
||||
/// <summary>
|
||||
/// تعداد شارژ پرداخت شده
|
||||
/// </summary>
|
||||
public int ChargePayCountInYear { set; get; }
|
||||
}
|
||||
public class UnitsByTransState
|
||||
{
|
||||
public Guid UnitId { set; get; }
|
||||
public string UnitName { set; get; }
|
||||
public string UnitUserMobile { set; get; }
|
||||
public string UnitUserFullName { set; get; }
|
||||
public int ChargeReminigCount { set; get; }
|
||||
}
|
||||
*/
|
||||
}
|
||||
278
Complex.Application/Services/Unit/UnitService.cs
Normal file
278
Complex.Application/Services/Unit/UnitService.cs
Normal file
@@ -0,0 +1,278 @@
|
||||
using AutoMapper;
|
||||
using Complex.Application.Services.Basic;
|
||||
using Complex.Application.Utility;
|
||||
using Complex.Common.Dto;
|
||||
using Complex.Domain.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Complex.Application.Complex
|
||||
{
|
||||
public interface IUnitService
|
||||
{
|
||||
/// <summary>
|
||||
/// ثبت توسط مدیر ساختمان
|
||||
/// </summary>
|
||||
/// <param name="unitDto"></param>
|
||||
/// <returns></returns>
|
||||
ResultDto<Guid> InsertUnit(string adminUserId, UnitDto unitDto);
|
||||
/// <summary>
|
||||
/// ویرایش توسط مدیر ساختمان
|
||||
/// </summary>
|
||||
/// <param name="unitDto"></param>
|
||||
/// <returns></returns>
|
||||
ResultDto<bool> AdminEditUnit(string adminUserId, UnitDto unitDto);
|
||||
/// <summary>
|
||||
/// ویرایش توسط مالک
|
||||
/// </summary>
|
||||
/// <param name="unitDto"></param>
|
||||
/// <returns></returns>
|
||||
ResultDto<bool> OwnerEditUnit(string UserId, UnitDto unitDto);
|
||||
/// <summary>
|
||||
/// ویرایش توسط مستاجر
|
||||
/// </summary>
|
||||
/// <param name="unitDto"></param>
|
||||
/// <returns></returns>
|
||||
ResultDto<bool> TenantEditUnit(string UserId, UnitDto unitDto);
|
||||
ResultDto<List<UnitDto>> UnitList(string userId, UnitRequestList unitRequest);
|
||||
}
|
||||
public class UnitService : IUnitService
|
||||
{
|
||||
private readonly IComplexDBContext _complexDBContext;
|
||||
private readonly CostService _costService;
|
||||
private IMapper _mapper;
|
||||
|
||||
public UnitService(IComplexDBContext complexDBContext, IMapper mapper, CostService costService)
|
||||
{
|
||||
_complexDBContext = complexDBContext;
|
||||
_costService = costService;
|
||||
_mapper = mapper;
|
||||
}
|
||||
public ResultDto<List<UnitDto>> UnitList(string userId, UnitRequestList unitRequest)
|
||||
{
|
||||
var today = PersianDate.GetToday();
|
||||
var IsUserInComplex = _complexDBContext.Units.Where(u => u.ComplexId == unitRequest.ComplexId
|
||||
&& (u.OwnerId == userId || u.TenantId == userId))
|
||||
.Select(a => a.ComplexId)
|
||||
.Union(_complexDBContext.ComplexManagers.Where(cm => cm.ComplexId == unitRequest.ComplexId
|
||||
&& string.Compare(cm.EndDate, today) >= 0
|
||||
&& string.Compare(cm.StartDate, today) <= 0)
|
||||
.Where(u => u.ManagerMobileNumberId == userId)
|
||||
.Select(u => u.ComplexId));
|
||||
|
||||
if (IsUserInComplex.Count() == 0)
|
||||
return new ResultDto<List<UnitDto>>
|
||||
{
|
||||
Data = null,
|
||||
IsSuccess = false,
|
||||
Message = "درخواست نامعتبر"
|
||||
};
|
||||
|
||||
var units = from u in _complexDBContext.Units.Include(u => u.Owner).Include(u => u.Tenant)
|
||||
.Include(u => u.State)
|
||||
where u.ComplexId == unitRequest.ComplexId
|
||||
select u;
|
||||
if (unitRequest.Id.HasValue)
|
||||
units = units.Where(u => u.Id == unitRequest.Id);
|
||||
|
||||
if (unitRequest.OwnerId.IsNotNullOrEmpty())
|
||||
units = units.Where(u => u.OwnerId == unitRequest.OwnerId);
|
||||
if (unitRequest.TenantId.IsNotNullOrEmpty())
|
||||
units = units.Where(u => u.TenantId == unitRequest.TenantId);
|
||||
|
||||
var unitObjs = units.ToList().Select(u => new UnitDto
|
||||
{
|
||||
ComplexId = u.ComplexId,
|
||||
UnitName = u.UnitName,
|
||||
Id = u.Id,
|
||||
AreaMeter = u.AreaMeter,
|
||||
TenantId = u.TenantId,
|
||||
EmergencyTels = u.EmergencyTels,
|
||||
Floor = u.Floor,
|
||||
InsertTime = Convert.ToDateTime(_complexDBContext.Entry(u).Property("InsertTime").CurrentValue),
|
||||
UpdateTime = Convert.ToDateTime(_complexDBContext.Entry(u).Property("UpdateTime").CurrentValue),
|
||||
//InsertTime = u.InsertTime,
|
||||
IsActive = u.IsActive,
|
||||
ManagerDescription = u.ManagerDescription,
|
||||
ParkingAreaMeter = u.ParkingAreaMeter,
|
||||
PublicState = u.PublicState,
|
||||
StateTitle = u.StateId.HasValue ? u.State.Title : "",
|
||||
StateId = u.StateId,
|
||||
YardMeter = u.YardMeter,
|
||||
TenantNameFamily = u.TenantId != null ? u.Tenant.FirstName + " " + u.Tenant.LastName : "",
|
||||
OwnerNameFamily = u.OwnerId != null ? u.Owner.FirstName + " " + u.Owner.LastName : "",
|
||||
OwnerId = u.OwnerId,
|
||||
});
|
||||
try
|
||||
{
|
||||
return new ResultDto<List<UnitDto>>
|
||||
{
|
||||
Data = unitObjs.ToList(),
|
||||
IsSuccess = true,
|
||||
//RowCount =
|
||||
};
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new ResultDto<List<UnitDto>>
|
||||
{
|
||||
Message = ex.InnerException != null ? ex.InnerException.Message + Environment.NewLine + ex.InnerException.Data :
|
||||
ex.Message + Environment.NewLine + ex.Data,
|
||||
IsSuccess = false
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public ResultDto<Guid> InsertUnit(string adminUserId, UnitDto unitDto)
|
||||
{
|
||||
var unit = _mapper.Map<Unit>(unitDto);
|
||||
var complexManager = _complexDBContext.ComplexManagers.Where(c => c.ComplexId == unit.ComplexId)
|
||||
.Select(cm => cm.ManagerMobileNumberId).ToList();
|
||||
if (!complexManager.Any(m => m == adminUserId))
|
||||
return new ResultDto<Guid>
|
||||
{
|
||||
Message = "عدم دسترسی",
|
||||
IsSuccess = false
|
||||
};
|
||||
//unit.InsertTime = DateTime.Now;
|
||||
_complexDBContext.Units.Add(unit);
|
||||
_complexDBContext.SaveChanges();
|
||||
//محاسبه شارژهای اون یونیت
|
||||
|
||||
var nowDate = DateOnly.FromDateTime(DateTime.Now);
|
||||
|
||||
//وقتی واحد تازه ثبت شده پس در مدیریت شارژ قابلیت ثبت اختصاصی برای خودش نداشته پس باید شارژ عمومی برایش تعریف شود
|
||||
// اگر خواست میتواند برایش به صورت اختصاصی هم ثبت کند که اون موقع برایش محاسبه مجدد خواهد شد
|
||||
var costCycleDto = _costService.CostCyclsList(unit.ComplexId, nowDate, nowDate, null).Data
|
||||
.FirstOrDefault(c => c.UnitIds == null);
|
||||
if (costCycleDto != null)
|
||||
{
|
||||
//var costCycle = new CostCycle
|
||||
//{
|
||||
// Amount=costCycleDto.Amount,
|
||||
|
||||
//};
|
||||
var costCycle=_mapper.Map<CostCycle>(costCycleDto);
|
||||
_costService.DefineUnitCharge(unit.Id, costCycle, true);
|
||||
}
|
||||
//
|
||||
return new ResultDto<Guid> { Data = unit.Id, IsSuccess = true, Message = "ثبت با موفقیت انجام شد" };
|
||||
}
|
||||
public ResultDto<bool> AdminEditUnit(string adminUserId, UnitDto unitDto)
|
||||
{
|
||||
var unit = _complexDBContext.Units.Include(u => u.Complex).ThenInclude(c => c.ComplexManagers).FirstOrDefault(u => u.Id == unitDto.Id);
|
||||
if (unit == null)
|
||||
return new ResultDto<bool> { Message = "مشکل در یافتن واحد", IsSuccess = false };
|
||||
|
||||
var today = PersianDate.GetToday();
|
||||
var complex = unit.Complex;
|
||||
if (complex.ComplexManagers == null || !complex.ComplexManagers.Any(m => m.ManagerMobileNumberId == adminUserId
|
||||
&& string.Compare(m.EndDate, today) >= 0))
|
||||
return new ResultDto<bool> { Message = "عدم دسترسی", IsSuccess = false };
|
||||
|
||||
|
||||
var oldUnitState = unit.PublicState;
|
||||
unit = _mapper.Map<Unit>(unitDto);
|
||||
unit.PublicState = oldUnitState;
|
||||
_complexDBContext.SaveChanges();
|
||||
|
||||
|
||||
//oldPayment را باید چه کار کرد؟؟؟؟!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
|
||||
return new ResultDto<bool> { Message = "ویرایش با موفقیت انجام شد", IsSuccess = true };
|
||||
}
|
||||
public ResultDto<bool> OwnerEditUnit(string UserId, UnitDto unitDto)
|
||||
{
|
||||
var unit = _complexDBContext.Units.FirstOrDefault(u => u.Id == unitDto.Id);
|
||||
if (unit == null)
|
||||
return new ResultDto<bool> { Message = "مشکل در یافتن واحد", IsSuccess = false };
|
||||
if (unit.OwnerId != UserId)
|
||||
return new ResultDto<bool> { Message = "عدم دسترسی", IsSuccess = false };
|
||||
|
||||
unit.AreaMeter = unitDto.AreaMeter;
|
||||
unit.YardMeter = unitDto.YardMeter;
|
||||
unit.ParkingAreaMeter = unitDto.ParkingAreaMeter;
|
||||
unit.EmergencyTels = unitDto.EmergencyTels;
|
||||
unit.Floor = unitDto.Floor;
|
||||
unit.ParkingAreaMeter = unitDto.ParkingAreaMeter;
|
||||
unit.PublicState = unitDto.PublicState;
|
||||
unit.YardMeter = unitDto.YardMeter;
|
||||
|
||||
|
||||
_complexDBContext.SaveChanges();
|
||||
return new ResultDto<bool> { Message = "ویرایش با موفقیت انجام شد", IsSuccess = true };
|
||||
}
|
||||
public ResultDto<bool> TenantEditUnit(string UserId, UnitDto unitDto)
|
||||
{
|
||||
var unit = _complexDBContext.Units.FirstOrDefault(u => u.Id == unitDto.Id);
|
||||
if (unit == null)
|
||||
return new ResultDto<bool> { Message = "مشکل در یافتن واحد", IsSuccess = false };
|
||||
if (unit.TenantId != UserId)
|
||||
return new ResultDto<bool> { Message = "عدم دسترسی", IsSuccess = false };
|
||||
|
||||
unit.PublicState = unitDto.PublicState;
|
||||
|
||||
_complexDBContext.SaveChanges();
|
||||
return new ResultDto<bool> { Message = "ویرایش با موفقیت انجام شد", IsSuccess = true };
|
||||
}
|
||||
}
|
||||
|
||||
public class UnitRequestList
|
||||
{
|
||||
public Guid? Id { set; get; }
|
||||
public Guid ComplexId { set; get; }
|
||||
public string? OwnerId { set; get; }
|
||||
public string? TenantId { set; get; }
|
||||
}
|
||||
|
||||
public class UnitDto
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public Guid ComplexId { set; get; }
|
||||
public string UnitName { set; get; }
|
||||
public ComplexEntity Complex { set; get; }
|
||||
/// <summary>
|
||||
/// ساکن
|
||||
/// </summary>
|
||||
public string? OwnerId { set; get; }
|
||||
/// <summary>
|
||||
/// شماره مستاجر
|
||||
/// </summary>
|
||||
public string? TenantId { set; get; }
|
||||
public bool IsActive { set; get; }
|
||||
/// <summary>
|
||||
/// متراژ کل
|
||||
/// </summary>
|
||||
public int? AreaMeter { set; get; }
|
||||
public string? EmergencyTels { set; get; }
|
||||
public int? ParkingAreaMeter { set; get; }
|
||||
/// <summary>
|
||||
/// متراژ حیاط
|
||||
/// </summary>
|
||||
public int? YardMeter { set; get; }
|
||||
public string? PublicState { set; get; }
|
||||
public int? StateId { set; get; }
|
||||
public string StateTitle { set; get; }
|
||||
public int? Floor { set; get; }
|
||||
//public string? UnitId { set; get; }
|
||||
public string? ManagerDescription { set; get; }
|
||||
//-----------------------------------------
|
||||
|
||||
/// <summary>
|
||||
/// نام و نام خانوادگی مالک
|
||||
/// </summary>
|
||||
public string OwnerNameFamily { set; get; }
|
||||
/// <summary>
|
||||
/// نام و نام خانوادگی مستاجر
|
||||
/// </summary>
|
||||
public string TenantNameFamily { set; get; }
|
||||
//public string StateByManager { set; get; }
|
||||
public DateTime? InsertTime { get; set; }
|
||||
public DateTime? UpdateTime { get; set; }
|
||||
}
|
||||
}
|
||||
16
Complex.Application/Services/UserSecurityService.cs
Normal file
16
Complex.Application/Services/UserSecurityService.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
//using System;
|
||||
//using System.Collections.Generic;
|
||||
//using System.Linq;
|
||||
//using System.Text;
|
||||
//using System.Threading.Tasks;
|
||||
|
||||
//namespace Complex.Application.Services
|
||||
//{
|
||||
// public class UserSecurityService
|
||||
// {
|
||||
// public void CheckComplexManager(string ManagerId,Guid ComplexId)
|
||||
// {
|
||||
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
50
Complex.Application/Services/Utility/ISendUserMessage.cs
Normal file
50
Complex.Application/Services/Utility/ISendUserMessage.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Complex.Application.Services.Utility
|
||||
{
|
||||
public interface ISendUserMessage
|
||||
{
|
||||
Task<Response<SendData>> Send(object message, string[] MobileNumber);
|
||||
Task<Response<SendData>> SendPattern(string patternCode, string MobileNumber, object values);
|
||||
}
|
||||
public class Response<T> where T : Data
|
||||
{
|
||||
public string status { get; set; }
|
||||
public string code { get; set; }
|
||||
public string message { get; set; }
|
||||
public T data { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return JsonSerializer.Serialize(this);
|
||||
}
|
||||
|
||||
public bool IsSuccessful
|
||||
{
|
||||
get
|
||||
{
|
||||
return data != null && data.error == null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class Data
|
||||
{
|
||||
public string error { get; set; }
|
||||
}
|
||||
|
||||
public class SendResponse : Response<SendData>
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public class SendData : Data
|
||||
{
|
||||
public string bulk_id { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user