public int CreatePendingShipments(ShipmentSearch search, int userid) { int shipments = 0; var contacts = dbContext.contacts.Where(c => (search.SelectedType != "Galleys" || c.galley_all) && (search.SelectedType != "Review" || c.review_all) && (search.SelectedType != "Desk" || c.desk_all) && (search.SelectedType != "Comp" || c.comp_all) && c.contact_shipment.Where(s => search.TitlesToCreateShipmentsFor.Contains(s.title_id) && s.type == search.SelectedType && s.status == "Pending").FirstOrDefault() == null ); if (contacts == null || contacts.Count() == 0) return shipments; foreach (int titleId in search.TitlesToCreateShipmentsFor) { foreach (contact c in contacts) { shipment ship = new shipment { contact_id = c.id, title_id = titleId, quantity = GetQuantityForSearchType(c, search), status = "Pending", type = search.SelectedType, createdat = DateTime.Now, createdby = userid, updatedat = DateTime.Now, updatedby = userid }; dbContext.shipments.Add(ship); shipments++; } } dbContext.SaveChanges(); return shipments; }
public void Insert(List<Shipment> list, int createdBy) { foreach (var model in list) { var obj = new shipment { title_id = model.TitleId, contact_id = model.ContactId, date_sent = model.DateSent, quantity = model.Quantity, should_followup = model.ShouldFollowUp, status = model.Status, type = model.Type, createdat = DateTime.Now, createdby = createdBy, updatedat = DateTime.Now, updatedby = createdBy, }; dbContext.shipments.Add(obj); } dbContext.SaveChanges(); }