Exemplo n.º 1
0
        /// <summary>
        /// 删除DeliveryAddress信息
        /// </summary>
        /// <param name="ids">要删除的Id编号</param>
        /// <returns>业务操作结果</returns>
        public async Task <OperationResult> DeleteDeliveryAddresss(params int[] ids)
        {
            ids.CheckNotNull("ids");
            await DeliveryAddressRepo.RecycleAsync(p => ids.Contains(p.Id));

            return(new OperationResult(OperationResultType.Success, "删除成功"));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 保存DeliveryAddress信息(新增/更新)
        /// </summary>
        /// <param name="updateForeignKey">更新时是否更新外键信息</param>
        /// <param name="dtos">要保存的DeliveryAddressDto信息</param>
        /// <returns>业务操作集合</returns>
        public async Task <OperationResult> SaveDeliveryAddresss(bool updateForeignKey = false, params DeliveryAddressDto[] dtos)
        {
            try
            {
                dtos.CheckNotNull("dtos");
                var addDtos    = dtos.Where(p => p.Id == 0).ToArray();
                var updateDtos = dtos.Where(p => p.Id != 0).ToArray();

                DeliveryAddressRepo.UnitOfWork.TransactionEnabled = true;

                Action <DeliveryAddressDto> checkAction = null;
                Func <DeliveryAddressDto, DeliveryAddress, DeliveryAddress> updateFunc = (dto, entity) =>
                {
                    if (dto.Id == 0 || updateForeignKey)
                    {
                        entity.UserInfo = UserInfoRepo.GetByKey(dto.UserInfoId);
                    }
                    return(entity);
                };
                if (addDtos.Length > 0)
                {
                    DeliveryAddressRepo.Insert(addDtos, checkAction, updateFunc);
                }
                if (updateDtos.Length > 0)
                {
                    DeliveryAddressRepo.Update(updateDtos, checkAction, updateFunc);
                }
                await DeliveryAddressRepo.UnitOfWork.SaveChangesAsync();

                return(new OperationResult(OperationResultType.Success, "保存成功"));
            }
            catch (Exception e)
            {
                return(new OperationResult(OperationResultType.Error, e.Message));
            }
        }