Example #1
0
        /// <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);
        }
Example #2
0
        private CemeteryAreasDTO LoadEntityData(CemeteryAreas entity)
        {
            var myDto = new CemeteryAreasDTO()
            {
                Id      = entity.Id,
                Name    = entity.Name,
                Alias   = entity.Alias,
                Remark  = entity.Remark,
                RowSort = entity.RowSort ?? "ASC"
            };

            myDto.TotalCount = _databaseContext.Tombstones.Count(a => a.AreaId == entity.Id);
            myDto.OrderCount = _databaseContext.Tombstones.Count(a => a.AreaId == entity.Id && a.PaymentStatusId == 2);
            myDto.SaleCount  = _databaseContext.Tombstones.Count(a => a.AreaId == entity.Id && a.PaymentStatusId == 3);
            myDto.BuryCount  = _databaseContext.Tombstones.Count(a => a.AreaId == entity.Id && a.PaymentStatusId == 5);

            return(myDto);
        }
Example #3
0
        /// <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);
        }
        private TombstoneDTO LoadEntityData(Tombstone entity, bool includeAll)
        {
            var myDto = new TombstoneDTO()
            {
                Id               = entity.Id,
                Name             = entity.Name,
                AreaId           = entity.AreaId,
                RowId            = entity.RowId,
                ColumnId         = entity.ColumnId,
                ParentId         = entity.ParentId,
                Alias            = entity.Alias,
                Remark           = entity.Remark,
                CustomerId       = entity.CustomerId,
                CustomerName     = entity.CustomerName,
                StoneText        = entity.StoneText,
                ExpiryDate       = entity.ExpiryDate,
                BuyDate          = entity.BuyDate,
                LastPaymentDate  = entity.LastPaymentDate,
                BuryDate         = entity.BuryDate,
                Width            = entity.Width,
                Height           = entity.Height,
                Acreage          = entity.Acreage,
                SecurityLevelId  = entity.SecurityLevelId,
                Image            = entity.Image,
                ServiceLevelId   = entity.ServiceLevelId,
                TypeId           = entity.TypeId,
                PaymentStatusId  = entity.PaymentStatusId,
                SortNum          = entity.SortNum,
                CustomerBuryDtos = new List <CustomerDTO>(),
                AreaSort         = "DESC",
                SupperManage     = entity.SupperManage,
                ManageLimit      = entity.ManageLimit
            };

            //包括所有关系
            if (includeAll)
            {
                if (entity.AreaId > 0)
                {
                    var cemeteryAreas = _databaseContext.CemeteryAreas.AsNoTracking().FirstOrDefault(a => a.Id == entity.AreaId);
                    CemeteryAreasDTO cemeteryAreasDto = null;
                    if (cemeteryAreas != null)
                    {
                        cemeteryAreasDto = new CemeteryAreasDTO
                        {
                            Id      = cemeteryAreas.Id,
                            Name    = cemeteryAreas.Name,
                            Alias   = cemeteryAreas.Alias,
                            Remark  = cemeteryAreas.Remark,
                            RowSort = cemeteryAreas.RowSort ?? "ASC"
                        };
                    }
                    myDto.AreaEntity = cemeteryAreasDto;
                    myDto.AreaSort   = cemeteryAreasDto.RowSort;
                }

                if (entity.RowId > 0)
                {
                    var             rows    = _databaseContext.CemeteryRows.AsNoTracking().FirstOrDefault(a => a.Id == entity.RowId);
                    CemeteryRowsDTO rowsDto = null;
                    if (rows != null)
                    {
                        rowsDto = new CemeteryRowsDTO
                        {
                            Id     = rows.Id,
                            Name   = rows.Name,
                            Alias  = rows.Alias,
                            Remark = rows.Remark
                        };
                    }
                    myDto.RowEntity = rowsDto;
                }
                if (entity.ColumnId > 0)
                {
                    var cols = _databaseContext.CemeteryColumns.AsNoTracking().FirstOrDefault(a => a.Id == entity.ColumnId);
                    CemeteryColumnsDTO closDto = null;
                    if (cols != null)
                    {
                        closDto = new CemeteryColumnsDTO
                        {
                            Id     = cols.Id,
                            Name   = cols.Name,
                            Alias  = cols.Alias,
                            Remark = cols.Remark
                        };
                    }
                    myDto.ColumnEntity = closDto;
                }
                if (entity.PaymentStatusId > 0)
                {
                    var paymentStatus = _databaseContext.PaymentStatus.AsNoTracking().FirstOrDefault(a => a.Id == entity.PaymentStatusId);
                    PaymentStatusDTO paymentStatusDto = null;
                    if (paymentStatus != null)
                    {
                        paymentStatusDto = new PaymentStatusDTO
                        {
                            Id     = paymentStatus.Id,
                            Name   = paymentStatus.Name,
                            Alias  = paymentStatus.Alias,
                            Remark = paymentStatus.Remark
                        };
                    }
                    myDto.PaymentStatusEntity = paymentStatusDto;
                }
                if (entity.SecurityLevelId > 0)
                {
                    var securityLevels = _databaseContext.SecurityLevels.AsNoTracking().FirstOrDefault(a => a.Id == entity.SecurityLevelId);
                    if (securityLevels != null)
                    {
                        myDto.SecurityLevelName = securityLevels.Name;
                    }
                }
                if (entity.ServiceLevelId > 0)
                {
                    var serviceLevels = _databaseContext.ServiceLevels.AsNoTracking().FirstOrDefault(a => a.Id == entity.ServiceLevelId);
                    if (serviceLevels != null)
                    {
                        myDto.ServiceLevelName = serviceLevels.Name;
                    }
                }

                //装载该墓碑落葬人
                var tombstoneBuriedPeopleMaps = _databaseContext.TombstoneBuriedPeopleMaps.Where(a => a.TombstoneId == myDto.Id);
                foreach (var tombstoneBuriedPeopleMap in tombstoneBuriedPeopleMaps)
                {
                    var customer = _databaseContext.Customers.FirstOrDefault(a => a.Id == tombstoneBuriedPeopleMap.BuriedCustomerId);
                    if (customer != null)
                    {
                        var customerDto = new CustomerDTO
                        {
                            Id         = customer.Id,
                            FirstName  = customer.FirstName,
                            MiddleName = customer.MiddleName,
                            LastName   = customer.LastName
                        };
                        myDto.CustomerBuryDtos.Add(customerDto);
                    }
                }
            }

            return(myDto);
        }