private long AddStyle(IUnitOfWork db, DateTime when, long?by) { var notEmptyLinkedStyles = LinkedStyles .Where(s => !String.IsNullOrEmpty(s.LinkedStyleString)) .ToList(); StyleViewModel.SetDefaultImage(ImageSet.Images); var dbStyle = new Style { StyleID = StyleId, Type = (int)StyleTypes.References, Name = Name, DropShipperId = DSHelper.DefaultPAId, Image = ImageSet.GetMainImageUrl(), //AdditionalImages = ImageSet.GetAdditionalImagesUrl(), ItemTypeId = (int)ItemType.Pajama, CreateDate = when, CreatedBy = by }; db.Styles.Add(dbStyle); db.Commit(); StyleViewModel.UpdateImages(db, dbStyle.Id, ImageSet.Images, when, by); db.StyleReferences.UpdateStyleReferencesForStyle(dbStyle.Id, notEmptyLinkedStyles, when, by); var styleItemToLinkedItems = RebuildStyleItems(db, dbStyle, notEmptyLinkedStyles); db.StyleItems.UpdateStyleItemsForStyle(dbStyle.Id, styleItemToLinkedItems.Select(si => si.StyleItem).ToList(), when, by); var styleItemReferences = BuildStyleItemReferences(db, dbStyle.Id, styleItemToLinkedItems); db.StyleItemReferences.UpdateStyleItemReferencesForStyle(dbStyle.Id, styleItemReferences, when, by); UpdateStyleFeatures(db, dbStyle.Id, LinkedStyles.Select(s => s.LinkedStyleId).ToList(), when, by); return(dbStyle.Id); }
private void UpdateStyle(IUnitOfWork db, Style style, DateTime when, long?by) { var notEmptyLinkedStyles = LinkedStyles .Where(s => !String.IsNullOrEmpty(s.LinkedStyleString)) .ToList(); StyleViewModel.SetDefaultImage(ImageSet.Images); style.StyleID = StyleId; style.Name = Name; style.Image = ImageSet.GetMainImageUrl(); //style.AdditionalImages = ImageSet.GetAdditionalImagesUrl(); style.UpdateDate = when; style.UpdatedBy = by; db.Commit(); StyleViewModel.UpdateImages(db, style.Id, ImageSet.Images, when, by); db.StyleReferences.UpdateStyleReferencesForStyle(style.Id, notEmptyLinkedStyles, when, by); var styleItemToLinkedItems = RebuildStyleItems(db, style, notEmptyLinkedStyles); db.StyleItems.UpdateStyleItemsForStyle(style.Id, styleItemToLinkedItems.Select(si => si.StyleItem).ToList(), when, by); var styleItemReferences = BuildStyleItemReferences(db, style.Id, styleItemToLinkedItems); db.StyleItemReferences.UpdateStyleItemReferencesForStyle(style.Id, styleItemReferences, when, by); }