public ReceivingSession CreateReceivingSession(int restorationPK, string userID) { try { ReceivingSession receivingSession = new ReceivingSession(userID, restorationPK); db.ReceivingSessions.Add(receivingSession); db.SaveChanges(); receivingSession = (from Rss in db.ReceivingSessions.OrderByDescending(unit => unit.ReceivingSessionPK) select Rss).FirstOrDefault(); return(receivingSession); } catch (Exception e) { throw e; } }
public void CreateEntryReceiving(List <IssuingController.Client_Box_List> list, ReceivingSession receivingSession) { BoxDAO boxDAO = new BoxDAO(); try { Dictionary <int, double> mapRestoredItems = new Dictionary <int, double>(); foreach (var items in list) { Box box = boxDAO.GetBoxByBoxID(items.BoxID); StoredBox sBox = boxDAO.GetStoredBoxbyBoxPK(box.BoxPK); foreach (var item in items.ListItem) { RestoredItem restoredItem = db.RestoredItems.Find(item.RestoredItemPK); if (!mapRestoredItems.ContainsKey(restoredItem.RestoredItemPK)) { mapRestoredItems.Add(restoredItem.RestoredItemPK, item.PlacedQuantity); } else { mapRestoredItems[restoredItem.RestoredItemPK] += item.PlacedQuantity; } Accessory accessory = db.Accessories.Find(restoredItem.AccessoryPK); Entry entry = new Entry(sBox, "Receiving", receivingSession.ReceivingSessionPK, true, item.PlacedQuantity, item.RestoredItemPK, accessory); db.Entries.Add(entry); } } foreach (var item in mapRestoredItems) { RestoredItem restoredItem = db.RestoredItems.Find(item.Key); if (item.Value != restoredItem.RestoredQuantity) { throw new Exception("TỔNG HÀNG LƯU KHO KHÔNG GIỐNG HÀNG ĐƯỢC TRẢ!"); } } db.SaveChanges(); } catch (Exception e) { throw e; } }