public static InventoryGroupViewModel BuildFrom(IUnitOfWork db, IList <long> styleIds) { var groupItems = db.Styles.GetAll().Where(st => styleIds.Contains(st.Id)) .Select(st => new InventoryGroupItemViewModel() { StyleId = st.Id, StyleString = st.StyleID }) .ToList(); var model = new InventoryGroupViewModel(); model.GroupItems = groupItems; return(model); }
public static CallMessagesResultVoid Apply(IUnitOfWork db, ISystemActionService actionService, InventoryGroupViewModel model, DateTime when, long?by) { var existGroup = db.StyleGroups.GetAll().FirstOrDefault(sg => sg.Name == model.Name); if (existGroup == null) { existGroup = new StyleGroup() { Name = model.Name, CreateDate = when, CreatedBy = by, }; db.StyleGroups.Add(existGroup); db.Commit(); } foreach (var groupItem in model.GroupItems) { var existGroupItem = db.StyleToGroups.GetAllAsDTO().FirstOrDefault(sgi => sgi.StyleGroupId == existGroup.Id && sgi.StyleId == groupItem.StyleId); if (existGroupItem == null) { var newStyleItem = new StyleToGroup() { StyleGroupId = existGroup.Id, StyleId = groupItem.StyleId, CreateDate = when, CreatedBy = by }; db.StyleToGroups.Add(newStyleItem); } } db.Commit(); return(CallMessagesResultVoid.Success()); }