private void FillGoods(Action action) { var ids = _actionGoodsGateway.SelectByAction(action.HeartId).Select(x => x.HeartId); var goods = ids.Select(x => _goodsGateway.SelectOne(x)); var idNames = goods.Select(x => new IdNamePair <int>(x.HeartId, x.Name)).ToList(); action.Goods = idNames; }
private void FillCats(Action action) { var catIds = _actionCategoryGateway.SelectByAction(action.HeartId).Select(x => x.CategoryId); var cats = catIds.Select(x => _categoryGateway.SelectOne(x)); var idNames = cats.Select(x => new IdNamePair <int>(x.HeartId, x.Name)).ToList(); action.Categories = idNames; }
private void FillManufaturers(Action action) { var manIds = _actionManufacturerGateway.SelectByAction(action.HeartId).Select(x => x.ManufacturerId); var mans = manIds.Select(x => _shopManufacturerService.GetManufacturer(x)); var idNames = mans.Select(x => new IdNamePair <int>(x.HeartId, x.Name)).ToList(); action.Manufacturers = idNames; }
private void FillData(Action action) { var heart = _heartService.GetHeart(action.HeartId); action.FillHeart(heart); FillGoods(action); FillCats(action); FillManufaturers(action); }
public int CreateAction(Action action) { action.Type = action.GetType().FullName; var dataRec = Mapper.Map <Data.Models.Action>(action); using (var ts = new TransactionScope()) { int id = action.HeartId = dataRec.HeartId = _heartService.CreateHeart(action); _actionGateway.Insert(dataRec); foreach (var catId in action.Categories.Select(x => x.ID)) { _actionCategoryGateway.Insert(new ActionCategory() { ActionId = id, CategoryId = catId }); } foreach (var goodsId in action.Goods.Select(x => x.ID)) { _actionGoodsGateway.Insert(new ActionGoods() { ActionId = id, HeartId = goodsId }); } foreach (var manId in action.Manufacturers.Select(x => x.ID)) { _actionManufacturerGateway.Insert(new ActionManufacturer() { ActionId = id, ManufacturerId = manId }); } ts.Complete(); return(id); } }
public void UpdateAction(Action action) { var dataAction = Mapper.Map <Data.Models.Action>(action); using (var ts = new TransactionScope()) { int actionId = action.HeartId; _heartService.UpdateHeart(action); _actionGateway.Update(dataAction); var oldCats = _actionCategoryGateway.SelectByAction(actionId); var newCats = action.Categories; foreach (var oldCat in oldCats) { if (newCats.All(x => x.ID != oldCat.CategoryId)) { _actionCategoryGateway.Delete(oldCat); } } foreach (var newCat in newCats) { if (oldCats.All(x => x.CategoryId != newCat.ID)) { _actionCategoryGateway.Insert(new ActionCategory() { ActionId = actionId, CategoryId = newCat.ID }); } } var oldGoods = _actionGoodsGateway.SelectByAction(actionId); var newGoods = action.Goods; foreach (var old in oldGoods) { if (newGoods.All(x => x.ID != old.HeartId)) { _actionGoodsGateway.Delete(old); } } foreach (var @new in newGoods) { if (oldGoods.All(x => x.HeartId != @new.ID)) { _actionGoodsGateway.Insert(new ActionGoods() { ActionId = actionId, HeartId = @new.ID }); } } var oldMans = _actionManufacturerGateway.SelectByAction(actionId); var newMans = action.Manufacturers; foreach (var oldMan in oldMans) { if (newMans.All(x => x.ID != oldMan.ManufacturerId)) { _actionManufacturerGateway.Delete(oldMan); } } foreach (var newMan in newMans) { if (oldMans.All(x => x.ManufacturerId != newMan.ID)) { _actionManufacturerGateway.Insert(new ActionManufacturer() { ActionId = actionId, ManufacturerId = newMan.ID }); } } ts.Complete(); } }