private void UpdateExistingBox(IUnitOfWork db, SealedBoxCounting dbBox, DateTime when, long?by) { dbBox.StyleId = StyleId; dbBox.BoxQuantity = BoxQuantity; dbBox.BatchTimeStatus = BatchTimeStatus; dbBox.CountByName = CountByName; dbBox.CountingDate = DateHelper.ConvertAppToUtc(CountingDate) ?? when; dbBox.UpdateDate = when; dbBox.UpdatedBy = by; db.Commit(); var boxItems = StyleItems.Items .Where(si => si.Breakdown.HasValue) .Select(si => new SealedBoxCountingItemDto() { Id = si.BoxItemId ?? 0, StyleItemId = si.Id, BreakDown = si.Breakdown ?? 0, }).ToList(); db.SealedBoxCountingItems.UpdateBoxItemsForBox(dbBox.Id, boxItems, when, by); }
private void AddNewBox(IUnitOfWork db, DateTime when, long?by) { var sealedBox = new SealedBoxCounting { StyleId = StyleId, BoxQuantity = BoxQuantity, BatchTimeStatus = BatchTimeStatus, CountByName = CountByName, CountingDate = DateHelper.ConvertAppToUtc(CountingDate) ?? when, CreateDate = when, CreatedBy = by }; db.SealedBoxCountings.Add(sealedBox); db.Commit(); var boxItems = StyleItems.Items .Where(si => si.Breakdown.HasValue) .Select(si => new SealedBoxCountingItemDto() { Id = si.BoxItemId ?? 0, StyleItemId = si.Id, BreakDown = si.Breakdown ?? 0, }).ToList(); db.SealedBoxCountingItems.UpdateBoxItemsForBox(sealedBox.Id, boxItems, when, by); }
public SealedBoxCountingViewModel(SealedBoxCounting item, List <StyleItemDTO> styleItems, List <SealedBoxCountingItemDto> boxItems) { Id = item.Id; StyleId = item.StyleId; BoxQuantity = item.BoxQuantity; BatchTimeStatus = item.BatchTimeStatus; CountByName = item.CountByName; CountingDate = item.CountingDate; UpdateDate = item.UpdateDate; CreateDate = item.CreateDate; BoxItemsQuantity = boxItems.Sum(b => b.BreakDown); StyleItems = new StyleItemCollection() { DisplayMode = StyleItemDisplayMode.BoxBreakdown, Items = styleItems .OrderBy(si => SizeHelper.GetSizeIndex(si.Size)) .ThenBy(si => si.Color) .Select(si => new StyleItemViewModel(si)).ToList() }; //Set boxes values foreach (var boxItem in boxItems) { var styleItem = StyleItems.Items.FirstOrDefault(si => si.Id == boxItem.StyleItemId); if (styleItem != null) { styleItem.Breakdown = boxItem.BreakDown; styleItem.BoxItemId = boxItem.Id; } } Breakdown = string.Join("-", StyleItems.Items .OrderBy(si => SizeHelper.GetSizeIndex(si.Size)) .ThenBy(si => si.Color) .Where(si => si.Breakdown.HasValue) .Select(si => si.Breakdown).ToList()); }