예제 #1
0
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="model"></param>
        public void Create(AreaDto model)
        {
            var entity = model.MapTo <AreaEntity>();

            entity.AreaUUID = Guid.NewGuid().ToString("N");
            var child = _areaRepository.Table.Where(a => a.ParentCode == model.ParentCode).ToList();

            var parentModel = _areaRepository.Table.FirstOrDefault(a => a.Code == model.ParentCode && !a.Deleted);

            if (parentModel != null)
            {
                entity.Code     = parentModel.Code + (child.Count + 1).ToString().PadLeft(4, '0');
                entity.AreaType = parentModel.AreaType + 1;
            }
            else
            {
                entity.Code     = (child.Count + 1).ToString().PadLeft(4, '0');
                entity.AreaType = 1;
            }
            entity.IsParent    = entity.AreaType == 11 ? "0" : "1";
            entity.Deleted     = false;
            entity.CreateTime  = DateTime.Now;
            entity.UpdateTime  = DateTime.Now;
            entity.SyncStatus  = false;
            entity.SyncVersion = 0;
            _areaRepository.Insert(entity);

            Synchronization(entity.AreaUUID);
        }
 /// <summary>
 /// 转换为地区实体
 /// </summary>
 /// <param name="dto">地区数据传输对象</param>
 public static Area ToEntity(this AreaDto dto)
 {
     if (dto == null)
     {
         return(new Area());
     }
     return(dto.MapTo(new Area(dto.Id.ToGuid(), "", 1)));
 }
예제 #3
0
 public static AreaEntity ToEntity(this AreaDto model, AreaEntity destination)
 {
     return(model.MapTo(destination));
 }
예제 #4
0
 public static AreaEntity ToEntity(this AreaDto model)
 {
     return(model.MapTo <AreaDto, AreaEntity>());
 }