public static SizeGroupViewModel Update(IUnitOfWork db, SizeGroupViewModel item, DateTime when, long?by) { if (item.Id.HasValue) { var group = db.SizeGroups.Get(item.Id.Value); if (group != null) { group.Name = item.Name; group.Departments = item.Departments; group.SortOrder = item.SortOrder; group.UpdateDate = when; group.UpdatedBy = by; db.Commit(); var itemTypes = item.ItemTypes != null?item.ItemTypes.Where(i => i.IsChecked).ToList() : new List <CheckedItemViewModel>(); MergeItemTypes(db, group.Id, itemTypes, when, by); return(item); } } return(null); }
public static SizeGroupViewModel Add(IUnitOfWork db, SizeGroupViewModel item, DateTime when, long?by) { var group = new SizeGroup { Name = item.Name, Departments = item.Departments, SortOrder = item.SortOrder, CreateDate = when, CreatedBy = by }; db.SizeGroups.Add(group); db.Commit(); var itemTypes = item.ItemTypes != null?item.ItemTypes.Where(i => i.IsChecked).ToList() : new List <CheckedItemViewModel>(); MergeItemTypes(db, group.Id, itemTypes, when, by); item.Id = group.Id; return(item); }