private void InsertNewItems(Ballroom ballroom, Dictionary <int, BallroomItem> newItems) { foreach (var item in newItems.Values) { ballroom.AddBallroomItem(item); } }
public void ProcessLayout(Ballroom ballroom, List <BallroomItem> viewItems) { var itemsDict = viewItems.ToDictionary(x => x.Id, y => y); ProcessBallroomItems(ballroom, itemsDict); InsertNewItems(ballroom, itemsDict); // list of items in this step is decreased by items that were used to update existing entities }
public void SaveLayout(string userId, Ballroom fromView) { var entity = _ballroomRepository.Find(userId).IfNull(() => CreateBallroom(userId)); entity.Update(fromView); _layoutService.ProcessLayout(entity, fromView.BallroomItems); _unitOfWork.Save(); }
private Ballroom CreateBallroom(string userId) { var ballroom = new Ballroom { UserId = userId, // user id must be added in this step BallroomItems = new List <BallroomItem>() // list has to be created to add new items }; _ballroomRepository.Insert(ballroom); return(ballroom); }
private void ProcessBallroomItems(Ballroom ballroom, Dictionary <int, BallroomItem> viewItems) { for (var i = ballroom.BallroomItems.Count - 1; i >= 0; i--) // since items can be removed from list - start iterating from the end of the list { var item = ballroom.BallroomItems[i]; BallroomItem newItem; (viewItems.TryGetValue(item.Id, out newItem)).IfTrueOrFalse(() => { UpdateItem(item, newItem); viewItems.Remove(newItem.Id); // and remove from items passed from the view }, () => DeleteItem(item)); } }
public BallroomModel MapBallroomEntity(Ballroom entity) { return(Mapper.Map <Ballroom, BallroomModel>(entity)); }