using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using AutoMapper;
|
using DTO;
|
using IServices;
|
using Microsoft.AspNetCore.Mvc.Rendering;
|
using Microsoft.EntityFrameworkCore;
|
using zhengcaioa.Models;
|
|
|
namespace Services
|
{
|
public class FiServiceService: IFiServiceService
|
{
|
private readonly zhengcaioaContext _context;
|
private readonly IMapper _mapper;
|
public FiServiceService(zhengcaioaContext context, IMapper mapper)
|
{
|
_context = context;
|
_mapper = mapper;
|
}
|
|
public ResultEntity save(FiServiceDTO dto)
|
{
|
ResultEntity resultEntity = new ResultEntity();
|
try
|
{
|
|
|
var entity = _mapper.Map<FiService>(dto);
|
|
|
if (String.IsNullOrEmpty(entity.Id))
|
{
|
entity.Id = Guid.NewGuid().ToString();
|
_context.FiServices.Add(entity);
|
}
|
else
|
{
|
var updateproject = _context.FiServices.Find(entity.Id);
|
|
updateproject.ServiceType = entity.ServiceType;
|
updateproject.ServiceTypeTwo = entity.ServiceTypeTwo;
|
updateproject.Feiyong = entity.Feiyong;
|
updateproject.Jifen = entity.Jifen;
|
|
|
updateproject.RecStatus = entity.RecStatus;
|
updateproject.Modifier = entity.Modifier;
|
updateproject.Modifytime = entity.Modifytime;
|
|
}
|
|
_context.SaveChanges();
|
resultEntity.ReturnID = entity.Id;
|
resultEntity.Result = true;
|
}
|
catch (Exception ex)
|
{
|
resultEntity.Result = false;
|
resultEntity.Message = "保存失败,请联系管理员";
|
|
}
|
return resultEntity;
|
}
|
|
public FiServiceDTO Get(string id)
|
{
|
|
var entity = _context.FiServices.Find(id);
|
|
if (entity.RecStatus != "A")
|
{
|
entity = new FiService();
|
}
|
|
var result = _mapper.Map<FiServiceDTO>(entity);
|
|
|
return result;
|
}
|
|
/// <summary>
|
/// 修改主表状态
|
/// </summary>
|
/// <param name="id">主id</param>
|
/// <param name="userid">用户</param>
|
/// <returns></returns>
|
public ResultEntity ModifyStatus(string id, string userid)
|
{
|
ResultEntity result = new ResultEntity();
|
result.Result = true;
|
|
var model = _context.FiServices.Find(id);
|
if (model != null)
|
{
|
model.RecStatus = "D";
|
model.Modifier = userid;
|
model.Modifytime = DateTime.Now;
|
_context.SaveChanges();
|
}
|
|
return result;
|
}
|
|
/// <summary>
|
/// 获取所有有效合作客户
|
/// </summary>
|
/// <returns></returns>
|
public List<FiServiceDTO> GetList(string service_type = "", string service_type_two = "")
|
{
|
List<FiServiceDTO> result = new List<FiServiceDTO>();
|
|
|
var listFiServices = _context.FiServices.Where(r => r.RecStatus == "A" && (string.IsNullOrEmpty(service_type) || r.ServiceType == service_type) && (string.IsNullOrEmpty(service_type_two) || r.ServiceType == service_type_two) ).OrderBy(x=>x.Createtime).ToList();
|
|
result = _mapper.Map<List<FiServiceDTO>>(listFiServices);
|
|
return result;
|
}
|
}
|
}
|