/// <summary> /// 效验用户登录信息 /// </summary> /// <param name="userDto"></param> /// <returns></returns> public DataControlResult <UserDTO> CheckUserLogin(UserDTO userDto) { var result = new DataControlResult <UserDTO>(); try { var user = _databaseContext.Users.FirstOrDefault(a => a.LoginName == userDto.LoginName && a.Password == userDto.Password); if (user != null) { result.ResultOutDto = _userMapper.Map(user, true); result.code = MyErrorCode.ResOK; result.msg = string.Empty; result.success = true; } else { result.ResultOutDto = null; result.code = MyErrorCode.LoginFail; result.msg = string.Empty; result.success = false; } } catch (Exception ex) { result.code = MyErrorCode.ResDBError; result.msg = ex.Message; result.success = false; result.ResultOutDto = null; return(result); } return(result); }
/// <summary> /// 墓碑解除落葬 /// </summary> /// <param name="tombstoneId"></param> /// <param name="customerIds"></param> /// <returns></returns> public DataControlResult <TombstoneBuriedPeopleMapDTO> UnburyPeopleTombstone(int tombstoneId, List <int> customerIds) { var result = new DataControlResult <TombstoneBuriedPeopleMapDTO>(); try { var tombstoneBuriedPeopleMaps = _databaseContext.TombstoneBuriedPeopleMaps.Where(a => customerIds.Contains(a.BuriedCustomerId) && a.TombstoneId == tombstoneId); foreach (var tombstoneBuriedPeopleMap in tombstoneBuriedPeopleMaps) { _databaseContext.TombstoneBuriedPeopleMaps.Remove(tombstoneBuriedPeopleMap); result.ResultOutDtos.Add(_tombstoneBuriedPeopleMapMapper.Map(tombstoneBuriedPeopleMap, false)); } _databaseContext.SaveChanges(); result.ResultOutDto = null; result.code = MyErrorCode.ResOK; result.msg = string.Empty; result.success = true; } catch (Exception ex) { result.code = MyErrorCode.ResDBError; result.msg = ex.Message; result.success = false; return(result); } return(result); }
/// <summary> /// 更新客户信息 /// </summary> /// <param name="csDto"></param> /// <returns></returns> public DataControlResult <CustomerDTO> Update(CustomerDTO csDto) { var result = new DataControlResult <CustomerDTO>(); try { var customer = _databaseContext.Customers.SingleOrDefault(n => n.Id == csDto.Id); if (customer == null) { result.success = false; result.msg = "该客户不存在"; result.code = MyErrorCode.ResParamError; return(result); } #region 赋值 customer.FullName = csDto.FullName; customer.LastName = csDto.LastName; customer.FirstName = csDto.FirstName; customer.MiddleName = csDto.MiddleName; customer.Remark = csDto.Remark; customer.Telephone = csDto.Telephone; customer.Phone = csDto.Phone; customer.OtherPhone = csDto.OtherPhone; customer.Address = csDto.Address; customer.BuryDate = csDto.BuryDate; customer.DeathDate = csDto.DeathDate; customer.IDNumber = csDto.IDNumber; if (csDto.CustomerTypeId.HasValue && csDto.CustomerTypeId > 0) { customer.CustomerTypeId = csDto.CustomerTypeId; } if (csDto.LinkCustomerId.HasValue && csDto.LinkCustomerId > 0) { customer.LinkCustomerId = csDto.LinkCustomerId; } if (csDto.CustomerStatusId.HasValue && csDto.CustomerStatusId > 0) { customer.CustomerStatusId = csDto.CustomerStatusId; } if (csDto.NationalityId.HasValue && csDto.NationalityId > 0) { customer.NationalityId = csDto.NationalityId; } #endregion _databaseContext.SaveChanges(); result.ResultOutDto = _customerMapper.Map(customer, false);; result.code = MyErrorCode.ResOK; result.msg = string.Empty; result.success = true; } catch (Exception ex) { result.code = MyErrorCode.ResDBError; result.msg = ex.Message; result.success = false; return(result); } return(result); }
/// <summary> /// 墓碑落葬 /// </summary> /// <param name="tombstoneId"></param> /// <returns></returns> public DataControlResult <TombstoneDTO> BuryTombstone(int tombstoneId, DateTime buryDate, int manageLimit, bool supperManage) { //判断墓碑是否为双人墓碑 状态是否为部分落葬 var tombstone = _databaseContext.Tombstones.FirstOrDefault(a => a.Id == tombstoneId); var result = new DataControlResult <TombstoneDTO>(); if (tombstone == null) { result.success = false; result.msg = "该墓碑不存在"; result.code = MyErrorCode.ResParamError; return(result); } if (tombstone.TypeId == 2) //双人墓 { if (tombstone.PaymentStatusId == 4) //部分落葬 { return(JobManageTombstone(tombstoneId, 5, buryDate, manageLimit, supperManage)); } else { return(JobManageTombstone(tombstoneId, 4, buryDate, manageLimit, supperManage)); } } else { return(JobManageTombstone(tombstoneId, 5, buryDate, manageLimit, supperManage)); } }
/// <summary> /// 新建客户 /// </summary> /// <param name="csDto"></param> /// <returns></returns> public DataControlResult <CustomerDTO> Create(CustomerDTO csDto) { var result = new DataControlResult <CustomerDTO>(); try { #region 赋值 var customer = new Customer { FullName = csDto.FullName, LastName = csDto.LastName, FirstName = csDto.FirstName, MiddleName = csDto.MiddleName, Remark = csDto.Remark, Telephone = csDto.Telephone, Phone = csDto.Phone, OtherPhone = csDto.OtherPhone, Address = csDto.Address, BuryDate = csDto.BuryDate, DeathDate = csDto.DeathDate, IDNumber = csDto.IDNumber }; if (csDto.CustomerTypeId.HasValue && csDto.CustomerTypeId > 0) { customer.CustomerTypeId = csDto.CustomerTypeId; } if (csDto.LinkCustomerId.HasValue && csDto.LinkCustomerId > 0) { customer.LinkCustomerId = csDto.LinkCustomerId; } if (csDto.CustomerStatusId.HasValue && csDto.CustomerStatusId > 0) { customer.CustomerStatusId = csDto.CustomerStatusId; } if (csDto.NationalityId.HasValue && csDto.NationalityId > 0) { customer.NationalityId = csDto.NationalityId; } #endregion _databaseContext.Customers.Add(customer); _databaseContext.SaveChanges(); result.ResultOutDto = _customerMapper.Map(customer, false); result.code = MyErrorCode.ResOK; result.msg = string.Empty; result.success = true; } catch (Exception ex) { result.code = MyErrorCode.ResDBError; result.msg = ex.Message; result.success = false; result.ResultOutDto = null; return(result); } return(result); }
/// <summary> /// 落葬、预定、出售等业务操作 /// </summary> /// <param name="tombstoneId"></param> /// <param name="paymentStatusId"></param> /// <returns></returns> private DataControlResult <TombstoneDTO> JobManageTombstone(int tombstoneId, int paymentStatusId, DateTime date, int?manageLimit, bool supperManage) { var result = new DataControlResult <TombstoneDTO>(); try { var tombstone = _databaseContext.Tombstones.SingleOrDefault(n => n.Id == tombstoneId); if (tombstone == null) { result.success = false; result.msg = "该墓碑不存在"; result.code = MyErrorCode.ResParamError; return(result); } #region 赋值 tombstone.PaymentStatusId = paymentStatusId; switch (paymentStatusId) { case 2: //预定 设置补交时间 tombstone.LastPaymentDate = date; break; case 3: //出售 设置出售时间 tombstone.BuyDate = date; break; case 5: //落葬 设置落葬时间 tombstone.BuryDate = date; tombstone.ManageLimit = manageLimit; tombstone.SupperManage = supperManage ? 1 : 0; break; } #endregion _databaseContext.SaveChanges(); result.ResultOutDto = _tombstoneMapper.Map(tombstone, false); result.code = MyErrorCode.ResOK; result.msg = string.Empty; result.success = true; } catch (Exception ex) { result.code = MyErrorCode.ResDBError; result.msg = ex.Message; result.success = false; return(result); } return(result); }
/// <summary> /// 更新角色信息 /// </summary> /// <param name="csDto"></param> /// <returns></returns> public DataControlResult <RoleDTO> Update(RoleDTO csDto) { var result = new DataControlResult <RoleDTO>(); using (TransactionScope tsScope = new TransactionScope()) { try { var role = _databaseContext.Roles.SingleOrDefault(n => n.Id == csDto.Id); if (role == null) { result.success = false; result.msg = "该角色不存在"; result.code = MyErrorCode.ResParamError; return(result); } #region 赋值 if (csDto.Name != null) { role.Name = csDto.Name; } #endregion _databaseContext.SaveChanges(); result.code = MyErrorCode.ResOK; result.ResultOutDto = _roleMapper.Map(role); result.msg = string.Empty; result.success = true; //赋予权限 if (csDto.FunctionDtos != null) { csDto.Id = result.ResultOutDto.Id; SetRolePermissionsFunctionMap(csDto); _databaseContext.SaveChanges(); } tsScope.Complete(); } catch (Exception ex) { result.code = MyErrorCode.ResDBError; result.msg = ex.Message; result.success = false; return(result); } } return(result); }
/// <summary> /// 新建角色 /// </summary> /// <param name="csDto"></param> /// <returns></returns> public DataControlResult <RoleDTO> Create(RoleDTO csDto) { var result = new DataControlResult <RoleDTO>(); //判断是否为重复登录名 var repeatRole = _databaseContext.Roles.FirstOrDefault(a => a.Name == csDto.Name); if (repeatRole != null) { result.code = MyErrorCode.ResDBError; result.msg = "重复的角色名"; result.success = false; result.ResultOutDto = null; return(result); } using (TransactionScope tsScope = new TransactionScope()) { try { #region 赋值 var role = new Role { Name = csDto.Name }; if (csDto.FunctionDtos != null) { SetRolePermissionsFunctionMap(csDto); } #endregion _databaseContext.Roles.Add(role); _databaseContext.SaveChanges(); result.ResultOutDto = _roleMapper.Map(role); result.code = MyErrorCode.ResOK; result.msg = string.Empty; result.success = true; tsScope.Complete(); } catch (Exception ex) { result.code = MyErrorCode.ResDBError; result.msg = ex.Message; result.success = false; result.ResultOutDto = null; return(result); } } return(result); }
/// <summary> /// 删除墓碑区域 /// </summary> /// <param name="csDtoList"></param> /// <returns></returns> public DataControlResult <CemeteryAreasDTO> Delete(List <CemeteryAreasDTO> csDtoList) { var result = new DataControlResult <CemeteryAreasDTO>(); var stopFlag = false; try { using (TransactionScope tsScope = new TransactionScope()) { foreach (var cemeteryAreasDto in csDtoList) { var cemeteryAreas = _databaseContext.CemeteryAreas.SingleOrDefault(n => n.Id == cemeteryAreasDto.Id); if (cemeteryAreas == null) { stopFlag = true; result.success = false; result.msg = "该墓碑区域不存在"; result.code = MyErrorCode.ResParamError; break; } //首先删除该区域下所有的墓碑 var tombstones = _databaseContext.Tombstones.Where(n => n.AreaId == cemeteryAreasDto.Id); foreach (var tombstone in tombstones) { _databaseContext.Tombstones.Remove(tombstone); } _databaseContext.CemeteryAreas.Remove(cemeteryAreas); } if (!stopFlag) { result.code = MyErrorCode.ResOK; result.msg = string.Empty; result.success = true; _databaseContext.SaveChanges(); tsScope.Complete(); } } } catch (Exception ex) { result.code = MyErrorCode.ResDBError; result.msg = ex.Message; result.success = false; return(result); } return(result); }
/// <summary> /// 续交管理费 /// </summary> /// <param name="csDto"></param> /// <returns></returns> public DataControlResult <TombstoneDTO> RenewManageLimit(TombstoneDTO csDto) { var result = new DataControlResult <TombstoneDTO>(); try { var tombstone = _databaseContext.Tombstones.SingleOrDefault(n => n.Id == csDto.Id); if (tombstone == null) { result.success = false; result.msg = "该墓碑不存在"; result.code = MyErrorCode.ResParamError; return(result); } //判断该墓碑是否存在 var repeatCol = _databaseContext.Tombstones.FirstOrDefault(a => a.AreaId == csDto.AreaId && a.RowId == csDto.RowId && a.ColumnId == csDto.ColumnId); if (repeatCol != null && repeatCol.Id != csDto.Id) { result.code = MyErrorCode.ResDBError; result.msg = "该墓碑行号已存在"; result.success = false; result.ResultOutDto = null; return(result); } #region 赋值 //if (csDto.ExpiryDate != null) tombstone.ExpiryDate = (DateTime)csDto.ExpiryDate; tombstone.ExpiryDate = tombstone.ExpiryDate.AddYears((int)csDto.ManageLimit); tombstone.ManageLimit += csDto.ManageLimit; #endregion _databaseContext.SaveChanges(); result.ResultOutDto = _tombstoneMapper.Map(tombstone, false); result.code = MyErrorCode.ResOK; result.msg = string.Empty; result.success = true; } catch (Exception ex) { result.code = MyErrorCode.ResDBError; result.msg = ex.Message; result.success = false; return(result); } return(result); }
/// <summary> /// 更新墓碑区域信息 /// </summary> /// <param name="csDto"></param> /// <returns></returns> public DataControlResult <CemeteryAreasDTO> Update(CemeteryAreasDTO csDto) { var result = new DataControlResult <CemeteryAreasDTO>(); try { var cemeteryAreas = _databaseContext.CemeteryAreas.SingleOrDefault(n => n.Id == csDto.Id); if (cemeteryAreas == null) { result.success = false; result.msg = "该墓碑区域不存在"; result.code = MyErrorCode.ResParamError; return(result); } //判断是否为重复区域 var repeat = _databaseContext.CemeteryAreas.FirstOrDefault(a => a.Name == csDto.Name || a.Alias == csDto.Alias); if (repeat != null && repeat.Id != cemeteryAreas.Id) { result.code = MyErrorCode.ResDBError; result.msg = "重复的区域名或别名编号"; result.success = false; result.ResultOutDto = null; return(result); } #region 赋值 cemeteryAreas.Name = csDto.Name; cemeteryAreas.Alias = csDto.Alias; cemeteryAreas.Remark = csDto.Remark; cemeteryAreas.RowSort = csDto.RowSort; #endregion _databaseContext.SaveChanges(); result.ResultOutDto = _cemeteryAreasMapper.Map(cemeteryAreas);; result.code = MyErrorCode.ResOK; result.msg = string.Empty; result.success = true; } catch (Exception ex) { result.code = MyErrorCode.ResDBError; result.msg = ex.Message; result.success = false; return(result); } return(result); }
/// <summary> /// 新建墓碑区域 /// </summary> /// <param name="csDto"></param> /// <returns></returns> public DataControlResult <CemeteryAreasDTO> Create(CemeteryAreasDTO csDto) { var result = new DataControlResult <CemeteryAreasDTO>(); //判断是否为重复区域 var repeat = _databaseContext.CemeteryAreas.FirstOrDefault(a => a.Name == csDto.Name || a.Alias == csDto.Alias); if (repeat != null) { result.code = MyErrorCode.ResDBError; result.msg = "重复的区域名或别名编号"; result.success = false; result.ResultOutDto = null; return(result); } try { #region 赋值 var cemeteryAreas = new CemeteryAreas { Alias = csDto.Alias, Name = csDto.Name, Remark = csDto.Remark, RowSort = csDto.RowSort }; #endregion _databaseContext.CemeteryAreas.Add(cemeteryAreas); _databaseContext.SaveChanges(); result.ResultOutDto = _cemeteryAreasMapper.Map(cemeteryAreas); result.code = MyErrorCode.ResOK; result.msg = string.Empty; result.success = true; } catch (Exception ex) { result.code = MyErrorCode.ResDBError; result.msg = ex.Message; result.success = false; result.ResultOutDto = null; return(result); } return(result); }
/// <summary> /// 墓碑排序 /// </summary> /// <param name="csDtoList"></param> /// <returns></returns> public DataControlResult <TombstoneDTO> SorTombstone(string[] idList) { var result = new DataControlResult <TombstoneDTO>(); try { using (TransactionScope tsScope = new TransactionScope()) { var submitFlag = true; for (int i = 0; i < idList.Length; i++) { TombstoneDTO dto = new TombstoneDTO { Id = int.Parse(idList[i]), SortNum = i }; var tempRl = Update(dto); if (!tempRl.success) { submitFlag = false; result = tempRl; } } if (submitFlag) { tsScope.Complete(); result.code = MyErrorCode.ResOK; result.msg = string.Empty; result.success = true; } } } catch (Exception ex) { result.code = MyErrorCode.ResDBError; result.msg = ex.Message; result.success = false; return(result); } return(result); }
/// <summary> /// 删除角色 /// </summary> /// <param name="csDtoList"></param> /// <returns></returns> public DataControlResult <RoleDTO> Delete(List <RoleDTO> csDtoList) { var result = new DataControlResult <RoleDTO>(); var stopFlag = false; try { foreach (var roleDto in csDtoList) { var role = _databaseContext.Roles.SingleOrDefault(n => n.Id == roleDto.Id); if (role == null) { stopFlag = true; result.success = false; result.msg = "该角色不存在"; result.code = MyErrorCode.ResParamError; break; } _databaseContext.Roles.Remove(role); } if (!stopFlag) { result.code = MyErrorCode.ResOK; result.msg = string.Empty; result.success = true; _databaseContext.SaveChanges(); } } catch (Exception ex) { result.code = MyErrorCode.ResDBError; result.msg = ex.Message; result.success = false; return(result); } return(result); }
/// <summary> /// 删除日志 /// </summary> /// <param name="dtoList"></param> /// <returns></returns> public DataControlResult<SysLogDTO> Delete(List<SysLogDTO> dtoList) { var result = new DataControlResult<SysLogDTO>(); var stopFlag = false; try { foreach (var dto in dtoList) { var log = _databaseContext.SysLogs.SingleOrDefault(n => n.Id == dto.Id); if (log == null) { stopFlag = true; result.success = false; result.msg = "该日志不存在"; result.code = MyErrorCode.ResParamError; break; } _databaseContext.SysLogs.Remove(log); } if (!stopFlag) { result.code = MyErrorCode.ResOK; result.msg = string.Empty; result.success = true; _databaseContext.SaveChanges(); } } catch (Exception ex) { result.code = MyErrorCode.ResDBError; result.msg = ex.Message; result.success = false; return result; } return result; }
/// <summary> /// 更新日志信息 /// </summary> /// <param name="dto"></param> /// <returns></returns> public DataControlResult<SysLogDTO> Update(SysLogDTO dto) { var result = new DataControlResult<SysLogDTO>(); try { var log = _databaseContext.SysLogs.SingleOrDefault(n => n.Id == dto.Id); if (log == null) { result.success = false; result.msg = "该日志不存在"; result.code = MyErrorCode.ResParamError; return result; } #region 赋值 if (dto.Type > 0) { log.Type = dto.Type; } if (!string.IsNullOrEmpty(dto.ControlName)) { log.ControlName = dto.ControlName; } if (!string.IsNullOrEmpty(dto.Content)) { log.Content = dto.Content; } if (dto.UserId > 0) { log.UserId = dto.UserId; } #region 业务日志写入 if (!string.IsNullOrEmpty(dto.Applicanter)) { log.Applicanter = dto.Applicanter; } if (!string.IsNullOrEmpty(dto.BuryMan)) { log.BuryMan = dto.BuryMan; } if (!string.IsNullOrEmpty(dto.Telephone)) { log.Telephone = dto.Telephone; } if (!string.IsNullOrEmpty(dto.IDNumber)) { log.IDNumber = dto.IDNumber; } if (dto.Money.HasValue) { log.Money = dto.Money; } if (dto.ControllTid.HasValue && dto.ControllTid.Value > 0) { log.ControllTid = (int)dto.ControllTid; } if (!string.IsNullOrEmpty(dto.ControllIds)) { log.ControllIds = dto.ControllIds; } if (!string.IsNullOrEmpty(dto.BuryMan)) { log.BuryMan = dto.BuryMan; } if (dto.BuryDate.HasValue) { log.BuryDate = dto.BuryDate; } if (!string.IsNullOrEmpty(dto.Remark)) { log.Remark = dto.Remark; } if (!string.IsNullOrEmpty(dto.Remark2)) { log.Remark2 = dto.Remark2; } #endregion #endregion _databaseContext.SaveChanges(); result.code = MyErrorCode.ResOK; result.msg = string.Empty; result.success = true; } catch (Exception ex) { result.code = MyErrorCode.ResDBError; result.msg = ex.Message; result.success = false; return result; } return result; }
/// <summary> /// 新建日志 /// </summary> /// <param name="dto"></param> /// <returns></returns> public DataControlResult<SysLogDTO> Create(SysLogDTO dto) { var result = new DataControlResult<SysLogDTO>(); try { #region 赋值 var log = new SysLog { Type = dto.Type, ControlName = dto.ControlName, Content = dto.Content, UserId = dto.UserId, Date = DateTime.Now }; #region 业务日志写入 if (!string.IsNullOrEmpty(dto.Applicanter)) { log.Applicanter = dto.Applicanter; } if (!string.IsNullOrEmpty(dto.BuryMan)) { log.BuryMan = dto.BuryMan; } if (dto.BuryDate.HasValue) { log.BuryDate = dto.BuryDate; } if (!string.IsNullOrEmpty(dto.Telephone)) { log.Telephone = dto.Telephone; } if (!string.IsNullOrEmpty(dto.IDNumber)) { log.IDNumber = dto.IDNumber; } if (dto.Money.HasValue) { log.Money = dto.Money; } if (dto.ControllTid.HasValue && dto.ControllTid.Value > 0) { log.ControllTid = (int)dto.ControllTid; } if (!string.IsNullOrEmpty(dto.ControllIds)) { log.ControllIds = dto.ControllIds; } if (!string.IsNullOrEmpty(dto.Remark)) { log.Remark = dto.Remark; } if (!string.IsNullOrEmpty(dto.Remark2)) { log.Remark2 = dto.Remark2; } #endregion #endregion _databaseContext.SysLogs.Add(log); _databaseContext.SaveChanges(); result.ResultOutDto = _sysLogMapper.Map(log); result.code = MyErrorCode.ResOK; result.msg = string.Empty; result.success = true; } catch (Exception ex) { result.code = MyErrorCode.ResDBError; result.msg = ex.Message; result.success = false; result.ResultOutDto = null; return result; } return result; }
/// <summary> /// 新建用户 /// </summary> /// <param name="csDto"></param> /// <returns></returns> public DataControlResult <UserDTO> Create(UserDTO csDto) { var result = new DataControlResult <UserDTO>(); //判断是否为重复登录名 var repeatUser = _databaseContext.Users.FirstOrDefault(a => a.LoginName == csDto.LoginName); if (repeatUser != null) { result.code = MyErrorCode.ResDBError; result.msg = "重复的登录名"; result.success = false; result.ResultOutDto = null; return(result); } try { #region 赋值 var user = new User { Name = csDto.Name, LoginName = csDto.LoginName, Code = csDto.Code, Remark = csDto.Remark, Password = csDto.Password, Position = csDto.Position, Status = csDto.Status }; if (csDto.CreateDate != null) { user.CreateDate = (DateTime)csDto.CreateDate; } if (csDto.DepartmentId.HasValue && csDto.DepartmentId > 0) { user.DepartmentId = (int)csDto.DepartmentId; } //赋予权限 if (csDto.RoleDtos.Count > 0) { SetUserRole(csDto); } #endregion _databaseContext.Users.Add(user); _databaseContext.SaveChanges(); result.ResultOutDto = _userMapper.Map(user); result.code = MyErrorCode.ResOK; result.msg = string.Empty; result.success = true; } catch (Exception ex) { result.code = MyErrorCode.ResDBError; result.msg = ex.Message; result.success = false; result.ResultOutDto = null; return(result); } return(result); }
/// <summary> /// 更新用户信息 /// </summary> /// <param name="csDto"></param> /// <returns></returns> public DataControlResult <UserDTO> Update(UserDTO csDto) { var result = new DataControlResult <UserDTO>(); try { var user = _databaseContext.Users.SingleOrDefault(n => n.Id == csDto.Id); if (user == null) { result.success = false; result.msg = "该用户不存在"; result.code = MyErrorCode.ResParamError; return(result); } //判断是否为重复登录名 var repeatUser = _databaseContext.Users.FirstOrDefault(a => a.LoginName == csDto.LoginName); if (repeatUser != null && repeatUser.Id != user.Id) { result.code = MyErrorCode.ResDBError; result.msg = "重复的登录名"; result.success = false; result.ResultOutDto = null; return(result); } #region 赋值 if (csDto.Name != null) { user.Name = csDto.Name; } if (csDto.LoginName != null) { user.LoginName = csDto.LoginName; } if (csDto.Code != null) { user.Code = csDto.Code; } if (csDto.Remark != null) { user.Remark = csDto.Remark; } if (csDto.Password != null) { user.Password = csDto.Password; } if (csDto.Position != null) { user.Position = csDto.Position; } if (csDto.Status != null) { user.Status = csDto.Status; } //if (csDto.CreateDate != null) user.CreateDate = (DateTime)csDto.CreateDate; if (csDto.DepartmentId.HasValue && csDto.DepartmentId > 0) { user.DepartmentId = (int)csDto.DepartmentId; } //赋予权限 if (csDto.RoleDtos.Count > 0) { SetUserRole(csDto); } #endregion _databaseContext.SaveChanges(); result.code = MyErrorCode.ResOK; result.ResultOutDto = _userMapper.Map(user); result.msg = string.Empty; result.success = true; } catch (Exception ex) { result.code = MyErrorCode.ResDBError; result.msg = ex.Message; result.success = false; return(result); } return(result); }
/// <summary> /// 批量添加墓碑 /// </summary> /// <param name="areaId"></param> /// <param name="rowId"></param> /// <param name="typeId"></param> /// <param name="count"></param> /// <returns></returns> public DataControlResult <TombstoneDTO> CreateList(int areaId, int rowId, int typeId, int count) { var result = new DataControlResult <TombstoneDTO>(); var submitFlag = true; //获取当前区域,行所有的墓碑 var hadTombstones = _databaseContext.Tombstones.Where(a => a.AreaId == areaId && a.RowId == rowId); var satrIndex = 1; if (hadTombstones.Any()) { var hadTombstone = hadTombstones.Max(a => a.ColumnId); satrIndex = hadTombstone + 1; } var endIndex = satrIndex + count; if (endIndex > 99) { endIndex = 99; } using (TransactionScope tsScope = new TransactionScope()) { for (int i = satrIndex; i < endIndex; i++) { var area = _databaseContext.CemeteryAreas.FirstOrDefault(a => a.Id == areaId); var dto = new TombstoneDTO { Name = area.Name + rowId + "排" + i + "号", Alias = area.Name + rowId + "排" + i + "号", AreaId = areaId, RowId = rowId, ColumnId = i, SortNum = -1, TypeId = typeId, BuryDate = DateTime.Parse("1777-01-01"), BuyDate = DateTime.Parse("1777-01-01"), ExpiryDate = DateTime.Parse("1777-01-01"), LastPaymentDate = DateTime.Parse("1777-01-01"), SecurityLevelId = 1, ServiceLevelId = 1, PaymentStatusId = 1 }; var resultTemp = Create(dto); result.ResultOutDtos.Add(resultTemp.ResultOutDto); if (!resultTemp.success) { submitFlag = false; result.code = MyErrorCode.ResDBError; result.msg = "墓碑批量添加失败"; result.success = false; result.ResultOutDto = null; } } if (submitFlag) { tsScope.Complete(); result.code = MyErrorCode.ResOK; result.msg = string.Empty; result.success = true; } //result.ResultOutDtos.Add(_tombstoneMapper.Map(tombstoneBuriedPeopleMap, false)); } return(result); }
/// <summary> /// 更新墓碑信息 /// </summary> /// <param name="csDto"></param> /// <returns></returns> public DataControlResult <TombstoneDTO> Update(TombstoneDTO csDto) { var result = new DataControlResult <TombstoneDTO>(); try { var tombstone = _databaseContext.Tombstones.SingleOrDefault(n => n.Id == csDto.Id); if (tombstone == null) { result.success = false; result.msg = "该墓碑不存在"; result.code = MyErrorCode.ResParamError; return(result); } //判断该墓碑是否存在 var repeatCol = _databaseContext.Tombstones.FirstOrDefault(a => a.AreaId == csDto.AreaId && a.RowId == csDto.RowId && a.ColumnId == csDto.ColumnId); if (repeatCol != null && repeatCol.Id != csDto.Id) { result.code = MyErrorCode.ResDBError; result.msg = "该墓碑行号已存在"; result.success = false; result.ResultOutDto = null; return(result); } #region 赋值 if (csDto.Name != null) { tombstone.Name = csDto.Name; } if (csDto.Alias != null) { tombstone.Alias = csDto.Alias; } if (csDto.Remark != null) { tombstone.Remark = csDto.Remark; } if (csDto.CustomerName != null) { tombstone.CustomerName = csDto.CustomerName; } if (csDto.StoneText != null) { tombstone.StoneText = csDto.StoneText; } if (csDto.Image != null) { tombstone.Image = csDto.Image; } tombstone.Width = csDto.Width; tombstone.Height = csDto.Height; tombstone.Acreage = csDto.Width * csDto.Height; tombstone.Image = csDto.Image; tombstone.SortNum = csDto.SortNum; if (csDto.ExpiryDate != null) { tombstone.ExpiryDate = (DateTime)csDto.ExpiryDate; } if (csDto.BuyDate != null) { tombstone.BuyDate = (DateTime)csDto.BuyDate; } if (csDto.LastPaymentDate != null) { tombstone.LastPaymentDate = (DateTime)csDto.LastPaymentDate; } if (csDto.BuryDate != null) { tombstone.BuryDate = (DateTime)csDto.BuryDate; } if (csDto.AreaId.HasValue && csDto.AreaId > 0) { tombstone.AreaId = (int)csDto.AreaId; } if (csDto.RowId.HasValue && csDto.RowId > 0) { tombstone.RowId = (int)csDto.RowId; } if (csDto.ColumnId.HasValue && csDto.ColumnId > 0) { tombstone.ColumnId = (int)csDto.ColumnId; } if (csDto.CustomerId.HasValue && csDto.CustomerId > 0) { tombstone.CustomerId = (int)csDto.CustomerId; } if (csDto.SecurityLevelId.HasValue && csDto.SecurityLevelId > 0) { tombstone.SecurityLevelId = (int)csDto.SecurityLevelId; } if (csDto.ServiceLevelId.HasValue && csDto.ServiceLevelId > 0) { tombstone.ServiceLevelId = (int)csDto.ServiceLevelId; } if (csDto.TypeId.HasValue && csDto.TypeId > 0) { tombstone.TypeId = (int)csDto.TypeId; } if (csDto.PaymentStatusId.HasValue && csDto.PaymentStatusId > 0) { tombstone.PaymentStatusId = (int)csDto.PaymentStatusId; } if (csDto.ParentId.HasValue && csDto.ParentId > 0) { tombstone.ParentId = (int)csDto.ParentId; } #endregion _databaseContext.SaveChanges(); result.ResultOutDto = _tombstoneMapper.Map(tombstone, false); result.code = MyErrorCode.ResOK; result.msg = string.Empty; result.success = true; } catch (Exception ex) { result.code = MyErrorCode.ResDBError; result.msg = ex.Message; result.success = false; return(result); } return(result); }
/// <summary> /// 墓碑落葬 /// </summary> /// <param name="tombstoneId"></param> /// <param name="customerIds"></param> /// <returns></returns> public DataControlResult <TombstoneBuriedPeopleMapDTO> BuryPeopleTombstone(int tombstoneId, List <int> customerIds) { var result = new DataControlResult <TombstoneBuriedPeopleMapDTO>(); try { using (TransactionScope tsScope = new TransactionScope()) { var submitFlag = true; foreach (var customerId in customerIds) { var tombstoneBuriedPeopleMap = new TombstoneBuriedPeopleMap { TombstoneId = tombstoneId, BuriedCustomerId = customerId }; //判断该墓碑是否存在落葬关系? 存在解除再落葬 var tombRepeats = _databaseContext.TombstoneBuriedPeopleMaps.Where(a => a.TombstoneId == tombstoneId); foreach (var tombRepeat in tombRepeats) { _databaseContext.TombstoneBuriedPeopleMaps.Remove(tombRepeat); } //判断该客户是否存在落葬关系 var repeat = _databaseContext.TombstoneBuriedPeopleMaps.FirstOrDefault(a => a.BuriedCustomerId == customerId); if (repeat != null && repeat.TombstoneId != tombstoneId) { var customer = _databaseContext.Customers.FirstOrDefault(a => a.Id == customerId); var fullName = customer != null ? customer.LastName + customer.MiddleName + customer.FirstName : "未知"; result.code = MyErrorCode.ResDBError; result.msg = "客户:" + fullName + "(" + customerId + ")" + "已经落葬,如需更改请先解除落葬关系"; result.success = false; result.ResultOutDto = null; submitFlag = false; break; } _databaseContext.TombstoneBuriedPeopleMaps.Add(tombstoneBuriedPeopleMap); result.ResultOutDtos.Add(_tombstoneBuriedPeopleMapMapper.Map(tombstoneBuriedPeopleMap, false)); } _databaseContext.SaveChanges(); if (submitFlag) { tsScope.Complete(); result.code = MyErrorCode.ResOK; result.msg = string.Empty; result.success = true; } } return(result); } catch (Exception ex) { result.code = MyErrorCode.ResDBError; result.msg = ex.Message; result.success = false; return(result); } return(result); }
/// <summary> /// 新建墓碑 /// </summary> /// <param name="csDto"></param> /// <returns></returns> public DataControlResult <TombstoneDTO> Create(TombstoneDTO csDto) { var result = new DataControlResult <TombstoneDTO>(); //判断该墓碑是否存在 var repeat = _databaseContext.Tombstones.FirstOrDefault(a => a.Name == csDto.Name); if (repeat != null) { result.code = MyErrorCode.ResDBError; result.msg = "该墓碑名称已存在"; result.success = false; result.ResultOutDto = null; return(result); } //判断该墓碑是否存在 var repeatCol = _databaseContext.Tombstones.FirstOrDefault(a => a.AreaId == csDto.AreaId && a.RowId == csDto.RowId && a.ColumnId == csDto.ColumnId); if (repeatCol != null) { result.code = MyErrorCode.ResDBError; result.msg = "该墓碑行号已存在"; result.success = false; result.ResultOutDto = null; return(result); } try { #region 赋值 var tombstone = new Tombstone { Name = csDto.Name, Alias = csDto.Alias, Remark = csDto.Remark, CustomerName = csDto.CustomerName, StoneText = csDto.StoneText, Width = csDto.Width, Height = csDto.Height, Acreage = csDto.Width * csDto.Height, Image = csDto.Image, SortNum = csDto.SortNum, SupperManage = 0, ManageLimit = 0 }; if (csDto.ExpiryDate != null) { tombstone.ExpiryDate = (DateTime)csDto.ExpiryDate; } if (csDto.BuyDate != null) { tombstone.BuyDate = (DateTime)csDto.BuyDate; } if (csDto.LastPaymentDate != null) { tombstone.LastPaymentDate = (DateTime)csDto.LastPaymentDate; } if (csDto.BuryDate != null) { tombstone.BuryDate = (DateTime)csDto.BuryDate; } if (csDto.AreaId.HasValue && csDto.AreaId > 0) { tombstone.AreaId = (int)csDto.AreaId; } if (csDto.RowId.HasValue && csDto.RowId > 0) { tombstone.RowId = (int)csDto.RowId; } if (csDto.ColumnId.HasValue && csDto.ColumnId > 0) { tombstone.ColumnId = (int)csDto.ColumnId; } if (csDto.CustomerId.HasValue && csDto.CustomerId > 0) { tombstone.CustomerId = (int)csDto.CustomerId; } if (csDto.SecurityLevelId.HasValue && csDto.SecurityLevelId > 0) { tombstone.SecurityLevelId = (int)csDto.SecurityLevelId; } if (csDto.ServiceLevelId.HasValue && csDto.ServiceLevelId > 0) { tombstone.ServiceLevelId = (int)csDto.ServiceLevelId; } if (csDto.TypeId.HasValue && csDto.TypeId > 0) { tombstone.TypeId = (int)csDto.TypeId; } if (csDto.PaymentStatusId.HasValue && csDto.PaymentStatusId > 0) { tombstone.PaymentStatusId = (int)csDto.PaymentStatusId; } if (csDto.ParentId.HasValue && csDto.ParentId > 0) { tombstone.ParentId = (int)csDto.ParentId; } #endregion _databaseContext.Tombstones.Add(tombstone); _databaseContext.SaveChanges(); result.ResultOutDto = _tombstoneMapper.Map(tombstone, false); result.code = MyErrorCode.ResOK; result.msg = string.Empty; result.success = true; } catch (Exception ex) { result.code = MyErrorCode.ResDBError; result.msg = ex.Message; result.success = false; result.ResultOutDto = null; return(result); } return(result); }