public async Task <IActionResult> CreateBuy(DealModifyModel model) { var objectIdsToAdd = model.SelectedDealObjects .Select(o => o.ObjectId) .ToList(); var createModel = new DealCreateModel(model.Price, model.Comment, null, 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.Buy); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> UpdateBuy(int dealId, DealModifyModel modfyModel) { var currentDeliveryObjectsTask = _dealObjectProvider.GetDealObjects(dealId); var currentDeliveryObjects = (await currentDeliveryObjectsTask).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 updateModel = new DealUpdateModel(dealId, objectsToDelete, objectsToAdd, modfyModel.Price, modfyModel.Comment, null, 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.Buy); return(RedirectToAction(nameof(Index))); }