public async Task <IActionResult> UpdateSell(int dealId, SellDealModifyViewModel modfyModel) { var currentDeliveryObjectsTask = _dealObjectProvider.GetDealObjects(dealId); var createUserAccountTask = Task.FromResult(new DataProviderModel <CreateUserAccountModel>(new ResultMessage(0, MessageType.Information, ""))); if (modfyModel.AccountAction == AccountAction.New) { createUserAccountTask = _userProvider.CreateUserAccount(modfyModel.PaymentNumber.Value, modfyModel.PaymentType); } await Task.WhenAll(currentDeliveryObjectsTask, createUserAccountTask); var currentDeliveryObjects = currentDeliveryObjectsTask.Result.Model; var createUserAccount = createUserAccountTask.Result.Model; var objectsToDelete = currentDeliveryObjects .Where(c => modfyModel.SelectedDealObjects.All(s => s.ObjectId != c.ObjectId)) .Select(o => o.DealObjectId) .ToList(); var objectsToAdd = modfyModel.SelectedDealObjects .Where(s => currentDeliveryObjects.All(c => c.ObjectId != s.ObjectId)) .Select(o => o.ObjectId) .ToList(); var accountId = modfyModel.AccountAction == AccountAction.Existed ? modfyModel.UserAccountId.Value : createUserAccount.AccountId; var updateModel = new DealUpdateModel(dealId, objectsToDelete, objectsToAdd, modfyModel.Price, modfyModel.Comment, accountId, modfyModel.DeleveryTypeId, modfyModel.Size, modfyModel.Weight, modfyModel.AddressModel.City.CityCode, modfyModel.AddressModel.Locality.LocalityCode, modfyModel.AddressModel.RegionCode, modfyModel.AddressModel.Address, (DeleveryLocationType)modfyModel.AddressModel.DeliveryLocationType); await _dealProvider.UpdateDeal(updateModel, DealType.Sell); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> CreateSell(SellDealModifyViewModel model) { var createUserAccountTask = Task.FromResult(new DataProviderModel <CreateUserAccountModel>(new ResultMessage(0, MessageType.Information, ""))); if (model.AccountAction == AccountAction.New) { createUserAccountTask = _userProvider.CreateUserAccount(model.PaymentNumber.Value, model.PaymentType); } var createUserAccount = (await createUserAccountTask).Model; var accountId = model.AccountAction == AccountAction.Existed ? model.UserAccountId.Value : createUserAccount.AccountId; var objectIdsToAdd = model.SelectedDealObjects .Select(o => o.ObjectId) .ToList(); var createModel = new DealCreateModel(model.Price, model.Comment, accountId, model.DeleveryTypeId, model.Size, model.Weight, model.AddressModel.City.CityCode, model.AddressModel.Locality.LocalityCode, model.AddressModel.RegionCode, model.AddressModel.Address, (DeleveryLocationType)model.AddressModel.DeliveryLocationType, objectIdsToAdd); await _dealProvider.CreateDeal(createModel, DealType.Sell); return(RedirectToAction(nameof(Index))); }