zoukankan      html  css  js  c++  java
  • 修改信息,一些对于不需要改的字段处理

    如:我们编辑好一条数据,然后进行发布操作,这样在商城就能进行购买。

    修改:编辑资源保存的时候进行逻辑判断

    是否发布和资源状态两个字段不需要改变。

    如下面方法:

            /// <summary>
            ///     编辑资源信息
            /// </summary>
            [AbpAuthorize(ResourceAppPermissions.Resource_EditResource)]
            public virtual async Task UpdateResourceAsync(ResourceEditDto input)
            {
                if (input.PlaceOfDeliveryIds.Count < 1)
                {
                    throw new UserFriendlyException("提货点地址不可为空");

                }
                if (input.BidEndTime <= DateTime.Now)
                {
                    throw new UserFriendlyException("竞价结束时间不能小于当前时间");
                }
                if (!input.Id.HasValue)
                    throw new UserFriendlyException("编辑资源的标识Id不存在");

        // 查询一遍数据库

                var entity = await _resourceRepository.FirstOrDefaultAsync(input.Id.Value);
                if (input.ResourceImgIdForALi <= 0)
                {
                    input.ResourceImgIdForALi = entity.ResourceImgIdForALi;
                }

                if (DateTime.Now >= entity.BidStartTime)
                {
                    throw new UserFriendlyException("该资源正在竞价中,不能编辑!");
                }
                //if (entity.IsPublish)
                //    throw new UserFriendlyException("该资源已发布不能对其进行编辑操作");


                entity.ResourceAddresses = new List<ResourceAddress>();
                var address = await GetResourceAddresses(input.PlaceOfDeliveryIds);

                await _resourceAddressRepository.DeleteAsync(a => a.ResourceId == entity.Id);
                address.ForEach(a => entity.ResourceAddresses.Add(a));


                if (!input.UploadDataId.HasValue)
                {
                    await _resourceItemsRepository.DeleteAsync(a => a.ResourceId == entity.Id);
                }
                else
                {
                    if (input.UploadDataId != entity.UploadDataId)
                    {
                        await _resourceItemsRepository.DeleteAsync(a => a.ResourceId == entity.Id);

                        //判断用户上传的附件表模板
                        TestingExcel(input.UploadDataId.Value);

                        //生成资源子表
                        var items = CreateExcelResourceItems(input.UploadDataId.Value);

                        entity.ResourceItems = items;

                        entity.UploadDataId = input.UploadDataId;
                    }

                }
                //时间
                //input.BidStartTime = DateTime.Now;
                input.ResourceState = entity.ResourceState;
                input.IsPublish = entity.IsPublish;
                input.MapTo(entity);

                //todo:删除旧资源分类之前,判断本次传进来的资源分类与原来的资源分类
                //是否存在变动,存在变动则 删除原来的资源分类,否则直接跳过删除,不对已有
                //的资源分类做处理

                //获取当前资源拥有的资源分类Ids
                //var currentCategories = await _categoryManage.GetResourceInCategoriesAsync(entity);
                var currentCategories = await _resourceCategoryRepository.GetAll().Where(a => a.ResourceId == input.Id).Select(b => b.CategoryId).ToListAsync();


                await _resourceRepository.UpdateAsync(entity);
            }

    我之前就错误的认为,这个两个字段也需要前端传递过来,解决办法就是修改之前查询一遍数据库,把不需要改变的字段重新赋值就可以了!!!

  • 相关阅读:
    CoCreateInstace 返回未知注册类别错误
    WINCE USB驱动组入
    CreateEvent ResetEvent SetEvent
    AppWidget的范例
    ubuntu下解决无声音的方法
    计算几何与图形学有关的几种常用算法
    Android实现GPS的打开与关闭
    深入剖析Android动画(Animation) (闪烁、左右摇摆、上下晃动等效果)
    中兴手机Linux下开发的方法
    移动网络环境下ReadBuffer的使用
  • 原文地址:https://www.cnblogs.com/wendj/p/6737033.html
Copyright © 2011-2022 走看看