public ApiResponse <bool> TransferAsset(AssetTransactionModel model) { if (this.Member.Id != model.InUserId) { throw new Exception("当前用户必须为接收者"); } if (model.InUserId == model.OutUserId) { throw new Exception("转出者和接收者不能为相同用户"); } model.BusinessType = BusinessType.AssetTransfer; bool isProduction = false; if (ConfigurationManager.AppSettings["IsProduction"] != null && ConfigurationManager.AppSettings["IsProduction"].ToLower() == "true") { isProduction = true; } var result = this.AssetTransactionService.Add(model, isProduction); var response = new ApiResponse <bool>() { Result = result }; return(response); }
/// <summary> /// 添加 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool Add(AssetTransactionModel model, bool isProduction = false) { using (var dbContext = new MissionskyOAEntities()) { var asset = dbContext.Assets.Where(it => it.Id == model.AssetId).FirstOrDefault(); if (asset == null) { throw new Exception("指定的资产Id不存在."); } if (!asset.Status.HasValue || (asset.Status.HasValue && (AssetStatus)asset.Status.Value != AssetStatus.Normal)) { throw new Exception("此状态的资产不能进行转移操作."); } var entity = model.ToEntity(); entity.InUserIsConfirm = false; entity.OutUserIsConfirm = false; entity.CreatedTime = DateTime.Now; dbContext.AssetTransactions.Add(entity); asset.Status = (int)AssetStatus.WaitOut; dbContext.SaveChanges(); SendNotificationsToOutAndInUsers(dbContext, model.OutUserId, model.InUserId, false, isProduction); return(true); } }
public static AssetTransaction ToEntity(this AssetTransactionModel model) { var entity = new AssetTransaction() { Id = model.Id, AssetId = model.AssetId, BusinessType = (int)model.BusinessType, InUserId = model.InUserId, InUserIsConfirm = model.InUserIsConfirm, OutUserId = model.OutUserId, OutUserIsConfirm = model.OutUserIsConfirm, Description = model.Description }; return(entity); }
public static AssetTransactionModel ToModel(this AssetTransaction entity) { var model = new AssetTransactionModel() { Id = entity.Id, AssetId = entity.AssetId, InUserId = entity.InUserId, InUserIsConfirm = entity.InUserIsConfirm, OutUserId = entity.OutUserId, OutUserIsConfirm = entity.OutUserIsConfirm, Description = entity.Description }; if (entity.BusinessType.HasValue) { model.BusinessType = (BusinessType)entity.BusinessType.Value; } if (entity.Status.HasValue) { model.Status = (AssetTransactionStatus)entity.Status.Value; } return(model); }