예제 #1
0
        public ActionResult UpdateHousehold(int Id) //Launches 2nd page of OD call log
        {
            Client client = db.Clients.Find(Id);

            if (client == null)
            {
                RedirectToAction("Index");
            }

            HouseholdViewModel houseHold = new HouseholdViewModel()
            {
                ClientId = Id,
                // ReSharper disable once PossibleNullReferenceException
                LastName      = client.LastName,
                FirstName     = client.FirstName,
                Active        = client.Active,
                Age           = AppRoutines.GetAge(client.DateOfBirth, DateTime.Today),
                StreetNumber  = client.StreetNumber,
                StreetName    = client.StreetName,
                City          = client.City,
                Zip           = client.Zip,
                Phone         = client.Phone,
                Notes         = client.Notes,
                FamilyMembers = AppRoutines.GetFamilyMembers(client.Id)
            };
            var newMember = new FamilyMember();

            houseHold.FamilyMembers.Add(newMember);  // Blank line for adding new member.
            newMember.ClientId = -1;
            newMember.Delete   = false;
            return(View(houseHold)); // Launches page UpdateHousehold.cshtml
        }
예제 #2
0
        // GET: Household
        public ActionResult Index(int clientId)
        {
            var householdView = new List <HouseholdViewModel>();

            List <Client> clientList =
                db.Clients.Where(a => a.Active).OrderBy(n => n.LastName).ToList();

            foreach (var client in clientList)
            {
                var sqlString = "SELECT * FROM FamilyMembers ";
                sqlString += "WHERE Active > 0 AND ClientId =" + clientId;
                var          familyList      = db.Database.SqlQuery <FamilyMember>(sqlString).ToList();
                FamilyMember headOfHousehold = new FamilyMember()
                {
                    FirstName   = client.LastName,
                    LastName    = client.FirstName,
                    DateOfBirth = client.DateOfBirth,
                };
                familyList.Add(headOfHousehold);
                var familyMembers = new List <FamilyMember>();
                foreach (FamilyMember member in familyList)
                {
                    member.Age = AppRoutines.GetAge(member.DateOfBirth, DateTime.Today);
                    familyMembers.Add(member);
                }

                var household = new HouseholdViewModel()
                {
                    ClientId      = client.Id,
                    FirstName     = client.FirstName,
                    LastName      = client.LastName,
                    DateOfBirth   = client.DateOfBirth,
                    StreetNumber  = client.StreetNumber,
                    StreetName    = client.StreetName,
                    StreetToolTip = client.StreetName.Replace(" ", "\u00a0"),
                    City          = client.City,
                    CityToolTip   = client.City.Replace(" ", "\u00a0"),
                    Zip           = client.Zip,
                    Phone         = client.Phone,
                    PhoneToolTip  = client.Phone.Replace(" ", "\u00a0"),
                    FamilyMembers = familyMembers,
                    Notes         = client.Notes,
                    // (full length on mouseover)    \u00a0 is the Unicode character for NO-BREAK-SPACE.
                    NotesToolTip = client.Notes.Replace(" ", "\u00a0"),
                };

                var s = household.StreetName; // For display, abbreviate to 10 characters:
                s = s.Length <= 10 ? s : s.Substring(0, 10) + "...";
                household.StreetName = s;
                s = household.City; // For display, abbreviate to 11 characters:
                s = s.Length <= 11 ? s : s.Substring(0, 11) + "...";
                household.City = s;
                s = household.Phone; // For display, abbreviate to 12 characters:
                s = s.Length <= 12 ? s : s.Substring(0, 12) + "...";
                household.Phone = s;
                s = household.Notes; // For display, abbreviate to 12 characters:
                s = s.Length <= 12 ? s : s.Substring(0, 12) + "...";
                household.Notes = s;

                householdView.Add(household);
            }
            Session["OriginalModel"] = householdView;
            return(View(householdView));
        }
예제 #3
0
        // GET: Deliveries/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            Delivery delivery = db.Deliveries.Find(id);

            if (delivery == null)
            {
                return(HttpNotFound());
            }
            var viewModel = new DeliveryViewModel()
            {
                Id               = delivery.Id,
                ClientId         = delivery.ClientId,
                DeliveryDate     = delivery.DeliveryDate,
                ODNotes          = delivery.ODNotes,
                DriverNotes      = delivery.DriverNotes,
                DateDelivered    = delivery.DateDelivered,
                FamilyMembers    = AppRoutines.GetFamilyMembers(delivery.ClientId),
                FamilySelectList = AppRoutines.GetFamilySelectList(delivery.ClientId)
            };

            foreach (var mbr in viewModel.FamilyMembers)
            {
                mbr.Age = AppRoutines.GetAge(mbr.DateOfBirth, DateTime.Today);
                if (mbr.Age < 18)
                {
                    viewModel.KidsCount += 1;
                }
                if (mbr.Age >= 18 && mbr.Age < 60)
                {
                    viewModel.AdultsCount += 1;
                }
                if (mbr.Age >= 60)
                {
                    viewModel.SeniorsCount += 1;
                }
            }
            var client = db.Clients.Find(delivery.ClientId);

            if (client != null)
            {
                viewModel.Client            = client;
                viewModel.ClientNameAddress = client.LastName + ", " + client.FirstName
                                              + " " + client.StreetNumber + " " + client.StreetName + " " + client.Zip;
                viewModel.Notes = client.Notes;
            }

            if (delivery.FullBags != null)
            {
                viewModel.FullBags = (int)delivery.FullBags;
            }
            if (delivery.HalfBags != null)
            {
                viewModel.HalfBags = (int)delivery.HalfBags;
            }
            if (delivery.KidSnacks != null)
            {
                viewModel.KidSnacks = (int)delivery.KidSnacks;
            }
            if (delivery.GiftCardsEligible != null)
            {
                viewModel.GiftCardsEligible = (int)delivery.GiftCardsEligible;
            }

            return(View(viewModel));
        }
예제 #4
0
        // GET: Deliveries
        public ActionResult Index()
        {
            var listDeliveries = new List <Delivery>(db.Deliveries).Where(d => d.DateDelivered == null).OrderBy(d => d.DeliveryDate).ToList();
            // to add order .ThenBy(Zip) means storing the Zip in Client.cs AND Delivery/cs
            var listDeliveryViewModels = new List <DeliveryViewModel>();

            foreach (var delivery in listDeliveries)
            {
                var client = db.Clients.Find(delivery.ClientId);
                if (client != null)
                {
                    var deliveryView = new DeliveryViewModel
                    {
                        Id               = delivery.Id,
                        ClientId         = client.Id,
                        Client           = client,
                        DeliveryDate     = Convert.ToDateTime(Session["CallLogDate"]),
                        FamilyMembers    = AppRoutines.GetFamilyMembers(client.Id),
                        FamilySelectList = AppRoutines.GetFamilySelectList(client.Id),
                        Kids             = new List <FamilyMember>(),
                        Adults           = new List <FamilyMember>(),
                        Seniors          = new List <FamilyMember>()
                    };
                    foreach (var mbr in deliveryView.FamilyMembers)
                    {
                        mbr.Age = AppRoutines.GetAge(mbr.DateOfBirth, DateTime.Today);
                        if (mbr.Age < 18)
                        {
                            deliveryView.Kids.Add(mbr);
                            deliveryView.KidsCount += 1;
                        }

                        if (mbr.Age >= 18 && mbr.Age < 60)
                        {
                            deliveryView.Adults.Add(mbr);
                            deliveryView.AdultsCount += 1;
                        }

                        if (mbr.Age >= 60)
                        {
                            deliveryView.Seniors.Add(mbr);
                            deliveryView.SeniorsCount += 1;
                        }
                    }

                    deliveryView.KidsCount         = deliveryView.Kids.Count();
                    deliveryView.AdultsCount       = deliveryView.Adults.Count();
                    deliveryView.SeniorsCount      = deliveryView.Seniors.Count();
                    deliveryView.FullBags          = 0;
                    deliveryView.HalfBags          = 0;
                    deliveryView.KidSnacks         = 0;
                    deliveryView.GiftCards         = 0;
                    deliveryView.GiftCardsEligible = 0;                          // !!! calculate this value
                    deliveryView.DateLastDelivery  = DateTime.Today.AddDays(-7); // !!! calculate this value
                    deliveryView.DateLastGiftCard  = DateTime.Today.AddDays(-7); // !!! calculate this value
                    if (delivery.DriverId != null)
                    {
                        var driver = db.Users.Find(delivery.DriverId);
                        if (driver != null)
                        {
                            deliveryView.DriverName = driver.FullName;
                        }
                    }
                    else
                    {
                        deliveryView.DriverName = "(nobody yet)";
                    }

                    var userIid = System.Web.HttpContext.Current.User.Identity.GetUserId();
                    if (userIid != null)
                    {
                        var user = db.Users.Find(userIid);
                        deliveryView.User = user;
                    }
                    ;
                    deliveryView.FirstName    = client.FirstName;
                    deliveryView.LastName     = client.LastName;
                    deliveryView.StreetNumber = client.StreetNumber;
                    deliveryView.StreetName   = client.StreetName;
                    // (full length on mouseover)    \u00a0 is the Unicode character for NO-BREAK-SPACE.
                    deliveryView.StreetToolTip = client.StreetName.Replace(" ", "\u00a0");
                    deliveryView.City          = client.City;
                    deliveryView.CityToolTip   = client.City.Replace(" ", "\u00a0");
                    deliveryView.Zip           = client.Zip;
                    deliveryView.Phone         = client.Phone;
                    deliveryView.PhoneToolTip  = client.Phone.Replace(" ", "\u00a0");
                    string s;
                    if (client.Notes != null)
                    {
                        deliveryView.Notes        = client.Notes;
                        deliveryView.NotesToolTip = client.Notes.Replace(" ", "\u00a0");
                        s = deliveryView.Notes;
                        s = s.Length <= 12 ? s : s.Substring(0, 12) + "...";
                        deliveryView.Notes = s;
                    }

                    if (delivery.ODNotes != null)
                    {
                        deliveryView.ODNotes        = delivery.ODNotes;
                        deliveryView.ODNotesToolTip = delivery.ODNotes.Replace(" ", "\u00a0");
                        s = deliveryView.ODNotes;
                        s = s.Length <= 12 ? s : s.Substring(0, 12) + "...";
                        deliveryView.ODNotes = s;
                    }

                    if (delivery.DriverNotes != null)
                    {
                        deliveryView.DriverNotes        = delivery.DriverNotes;
                        deliveryView.DriverNotesToolTip = deliveryView.DriverNotes.Replace(" ", "\u00a0");
                        s = deliveryView.DriverNotes;  // For display, abbreviate to 12 characters:
                        s = s.Length <= 12 ? s : s.Substring(0, 12) + "...";
                        deliveryView.DriverNotes = s;
                    }

                    s = deliveryView.StreetName;
                    s = s.Length <= 9 ? s : s.Substring(0, 9) + "...";
                    deliveryView.StreetName = s;
                    s = deliveryView.City; // For display, abbreviate to 11 characters:
                    s = s.Length <= 10 ? s : s.Substring(0, 10) + "...";
                    deliveryView.City = s;
                    s = deliveryView.Phone; // For display, abbreviate to 12 characters:
                    s = s.Length <= 12 ? s : s.Substring(0, 12) + "...";
                    deliveryView.Phone = s;
                    listDeliveryViewModels.Add(deliveryView);
                }
            }
            return(View(listDeliveryViewModels));
        }