コード例 #1
0
        public async Task <ResultDto> Update(int id, WareInput item)
        {
            var result = new ResultDto {
                Message = ""
            };

            try
            {
                var ware = await _wareDomainService.Get(id);

                if (ware == null)
                {
                    result.Message = $"物品 {id} 不存在!";
                    return(result);
                }
                var content = ware.ComparisonTo(item);
                _mapper.Map(item, ware);

                if (ware.Effect == null)
                {
                    ware.Effect = "";
                }

                await _wareDomainService.Update(ware);

                await _operatorLogDomainService.AddSuccess(new OperatorLogEntity
                {
                    Type    = OperatorLogType.修改物品,
                    Content = $"Id = {id},Data = {content}"
                });

                await Commit();

                result.IsSuccess = true;
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
                await _operatorLogDomainService.AddError(new OperatorLogEntity
                {
                    Type    = OperatorLogType.修改物品,
                    Content = $"Data={JsonConvert.SerializeObject(item)},ErrorMessage={result.Message}"
                });
                await Commit();
            }
            return(result);
        }
コード例 #2
0
        public async Task <ResultDto> Add(WareInput item)
        {
            var result = new ResultDto {
                Message = ""
            };

            try
            {
                var ware = _mapper.Map <WareEntity>(item);
                if (ware.Effect == null)
                {
                    ware.Effect = "";
                }

                await _wareDomainService.Add(ware);

                await _operatorLogDomainService.AddSuccess(new OperatorLogEntity
                {
                    Type    = OperatorLogType.添加物品,
                    Content = JsonConvert.SerializeObject(item)
                });

                await Commit();

                result.IsSuccess = true;
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
                await _operatorLogDomainService.AddError(new OperatorLogEntity
                {
                    Type    = OperatorLogType.添加物品,
                    Content = $"Data={JsonConvert.SerializeObject(item)},ErrorMessage={result.Message}"
                });
                await Commit();
            }
            return(result);
        }