Exemplo n.º 1
0
        public FileResult CreateCsv(ShipmentSearch search)
        {
            search.SelectedTitles = search.SelectedTitlesCsv.Split(',').Select(int.Parse).ToArray();
            List<ShipmentCsvLine> items = data.GetPendingShipments(search);

            foreach (ShipmentCsvLine item in items)
            {
                item.SubscriberNumber = item.SubNumber.HasValue ? item.SubNumber.Value.ToString() : "";
                foreach (var title in item.TitleList)
                    item.Titles += title.TitleName + " (" + title.Quantity + "),";

                item.FollowUp = item.FollowUpShipments.Count() > 0 ? "Yes" : "No";

            }

            CsvFileDescription outputFileDescription = new CsvFileDescription
            {
                //SeparatorChar = '\t', // tab delimited
                EnforceCsvColumnAttribute = true
                // FirstLineHasColumnNames = true, // no column names in first record
                // FileCultureName = "en-US" // use formats used in The Netherlands
            };

            CsvContext cc = new CsvContext();
            using (MemoryStream ms = new MemoryStream())
            {
                using (TextWriter tw = new StreamWriter(ms))
                {
                    cc.Write(items, tw, outputFileDescription);
                }

                return File(ms.ToArray(), "text/csv", "PendingShipments.csv");
            }
        }
Exemplo n.º 2
0
        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;
        }
Exemplo n.º 3
0
 public ActionResult MarkSent(ShipmentSearch search)
 {
     search.SelectedTitles = search.SelectedTitlesCsv.Split(',').Select(int.Parse).ToArray();
     int total = data.MarkShipmentsSent(search, (Session["LoggedInUser"] as user).id);
     TempData["SuccessMessage"] = string.Format("\"{0}\" shipments were marked sent.", total);
     return RedirectToAction("Index");
 }
Exemplo n.º 4
0
        public ActionResult Index(ShipmentSearch search, string btnValue)
        {
            search.HideOptions = false;
            if (btnValue == "Find Marked Contacts")
            {
                search.ContactResults = data.SearchForContacts(search);
                if (search.ContactResults.Count() == 0)
                    search.Message = "No contacts matching your search found.";
                else
                    search.HideOptions = true;
            }
            else if (btnValue == "Find Pending Shipments" && search.SelectedTitles != null)
            {
                search.SelectedTitlesCsv = String.Join(",", search.SelectedTitles);
                search.ShipmentResults = data.SearchForShipments(search);
                if (search.ShipmentResults.Count() == 0)
                    search.Message = "No pending shipments matching your search found.";
                else
                    search.HideOptions = true;
            }
            else
                search.Message = "Unknown action";

            return View(search);
        }
Exemplo n.º 5
0
 public ActionResult Index(ShipmentSearch search)
 {
     return View(search);
 }
Exemplo n.º 6
0
 public ActionResult CreatePending(ShipmentSearch search)
 {
     int total = data.CreatePendingShipments(search, (Session["LoggedInUser"] as user).id);
     TempData["SuccessMessage"] = string.Format("\"{0}\" pending shipments were created.", total);
     return RedirectToAction("Index");
 }
Exemplo n.º 7
0
        public List<ShipmentCsvLine> GetPendingShipments(ShipmentSearch search)
        {
            if (search.SelectedTitles.Count() == 0)
                throw new ArgumentNullException();

            return dbContext.contacts.Where(c => c.contact_shipment.Where(
               s => search.SelectedTitles.Contains(s.title_id) && s.status == "Pending" && s.type == search.SelectedType).Count() > 0)
               .Select(c => new ShipmentCsvLine
               {
                   FirstName = c.firstname,
                   LastName = c.lastname,
                   SubNumber = c.is_subscriber ? c.sub_number : null,
                   AddressLine1 = c.is_primary ? c.addressline1 : c.addressline1_alt,
                   AddressLine2 = c.is_primary ? c.addressline2 : c.addressline2_alt,
                   State = c.is_primary ? c.state : c.state_alt,
                   Zip = c.is_primary ? c.zip : c.zip_alt,
                   Country = c.is_primary ? c.country : c.country_alt,
                   Title = c.is_primary ? c.title : c.title_alt,
                   City = c.is_primary ? c.city : c.city_alt,
                   Organization = c.is_primary ? c.organization : c.organization_alt,
                   TitleList = c.contact_shipment.Where(
                       s => search.SelectedTitles.Contains(s.title_id) && s.status == "Pending" && s.type == search.SelectedType)
                       .Select(s => new TitleToSend
                       {
                           TitleId = s.title_id,
                           TitleName = s.shipment_title.title1,
                           Quantity = s.quantity
                       }),
                   PrimaryEmail = c.email1,
                   AltEmail = c.email2,
                   FollowUpShipments = c.contact_shipment.Where(s => s.should_followup).Select(s => s.id)
               }).ToList();
        }
Exemplo n.º 8
0
 private int GetQuantityForSearchType(contact c, ShipmentSearch search)
 {
     if (search.SelectedType == "Galleys")
         return c.galley_copies ?? 1;
     if (search.SelectedType == "Review")
         return c.review_copies ?? 1;
     if (search.SelectedType == "Desk")
         return c.desk_copies ?? 1;
     if (search.SelectedType == "Comp")
         return c.comp_copies ?? 1;
     throw new ArgumentNullException();
 }
Exemplo n.º 9
0
        /// <summary>
        /// GET SHIPMENTS MARK SENT
        /// </summary>
        public IEnumerable<ShipmentDetails> SearchForShipments(ShipmentSearch search)
        {
            if (search.SelectedTitles.Count() == 0)
                return new List<ShipmentDetails>();

            return dbContext.contacts.Where(c => c.contact_shipment.Where(
               s => search.SelectedTitles.Contains(s.title_id) && s.status == "Pending" && s.type == search.SelectedType).Count() > 0)
               .Select(c => new ShipmentDetails
               {
                   SortName = c.lastname + ", " + c.firstname,
                   City = c.is_primary ? c.city : c.city_alt,
                   ContactId = c.id,
                   Organization = c.is_primary ? c.organization : c.organization_alt,
                   Titles = c.contact_shipment.Where(
                       s => search.SelectedTitles.Contains(s.title_id) && s.status == "Pending" && s.type == search.SelectedType)
                   .Select(s => new TitleToSend
                   {
                       TitleId = s.title_id,
                       TitleName = s.shipment_title.title1,
                       Quantity = s.quantity
                   })
               });
        }
Exemplo n.º 10
0
 /// <summary>
 /// GET CONTACTS MARK PENDING 
 /// </summary>
 public IEnumerable<ShipmentDetails> SearchForContacts(ShipmentSearch search)
 {
     return 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)
        )
        .Select(c => new ShipmentDetails
        {
            SortName = c.lastname + ", " + c.firstname,
            City = c.is_primary ? c.city : c.city_alt,
            ContactId = c.id,
            Organization = c.is_primary ? c.organization : c.organization_alt
        });
 }
Exemplo n.º 11
0
        public int MarkShipmentsSent(ShipmentSearch search, int userid)
        {
            int count = 0;
            if (search.SelectedTitles.Count() == 0)
                throw new ArgumentNullException();

            var ships = dbContext.shipments.Where(s => search.SelectedTitles.Contains(s.title_id) && s.status == "Pending" && s.type == search.SelectedType);

            foreach (shipment s in ships)
            {
                s.date_sent = DateTime.Now;
                s.should_followup = search.MarkAsFollowUp;
                s.updatedat = DateTime.Now;
                s.updatedby = userid;
                s.status = "Sent";
                count++;
            }
            dbContext.SaveChanges();
            return count;
        }