Ejemplo n.º 1
0
        public ActionResult Create([Bind(Include = "Id,FirstName,LastName,DateOfBirth,Active,ClientNote,Location")] HfedClient hfedClient)
        {
            //EF adding blank Foreign Key records: use raw SQL
            using (var context = new SenecaContext())
            {
                string cmdString = "INSERT INTO HfedClient (";
                cmdString += "FirstName,LastName,DateOfBirth,Active,ClientNote,Location_Id)";
                cmdString += " VALUES (";
                cmdString += "'" + hfedClient.FirstName + "','" + hfedClient.LastName + "',";
                cmdString += "'" + hfedClient.DateOfBirth + "',";
                if (hfedClient.Active)
                {
                    cmdString += "1,";
                }
                else
                {
                    cmdString += "0,";
                }

                if (!hfedClient.ClientNote.IsNullOrEmpty())
                {
                    cmdString += "'" + hfedClient.ClientNote.Replace("'", "''") + "',";
                }
                else
                {
                    cmdString += "'',";
                }
                cmdString += hfedClient.Location.Id + ")";
                context.Database.ExecuteSqlCommand(cmdString);
            }
            TempData["ClientLocationId"] = hfedClient.Location.Id;
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 2
0
        private HfedScheduleViewModel CheckForDuplicateClient(HfedScheduleViewModel schedule)
        {
            // Check for duplicate clients on same day
            var otherSchedules = db.HfedSchedules.Where(s => s.Date == schedule.Date &&
                                                        s.Id != schedule.Id).ToList();

            if (otherSchedules.Count > 0 && schedule.HfedClientsArray != null)
            {
                foreach (HfedSchedule otherSched in otherSchedules)
                {
                    otherSched.HfedClientsArray = otherSched.HfedClientIds.Split(',').ToArray();
                    foreach (var c in otherSched.HfedClientsArray)
                    {
                        foreach (var c1 in schedule.HfedClientsArray)
                        {
                            if (c == c1 && !c1.IsNullOrEmpty())
                            {
                                HfedClient dupClient = db.HfedClients.Find(Convert.ToInt32(c));
                                if (dupClient != null)
                                {
                                    schedule.ErrorMessage = dupClient.FullName
                                                            + " is already selected in another run on "
                                                            + otherSched.Date.ToShortDateString();

                                    schedule = GetDropDownData(schedule);
                                    return(schedule); // (for error functions)
                                }
                            }
                        }
                    }
                }
            }

            return(schedule);
        }
Ejemplo n.º 3
0
 public ActionResult Edit([Bind(Include = "Id,FirstName,LastName,DateOfBirth,Active,Location,ClientNote,NumberInHousehold")] HfedClient hfedClient)
 {
     if (ModelState.IsValid)
     {
         using (var context = new SenecaContext())
         {
             var query = @"UPDATE HfedClient"
                         + " SET FirstName=@FirstName,LastName=@LastName,DateOfBirth=@DateOfBirth,"
                         + "Active=@Active,ClientNote=@ClientNote,Location_Id=@Location_Id,"
                         + "NumberInHousehold=@NumberInHousehold"
                         + " WHERE Id = " + hfedClient.Id;
             context.Database.ExecuteSqlCommand(query,
                                                new SqlParameter("@FirstName", hfedClient.FirstName),
                                                new SqlParameter("@LastName", hfedClient.LastName),
                                                new SqlParameter("@DateOfBirth", hfedClient.DateOfBirth.ToShortDateString()),
                                                new SqlParameter("@Active", hfedClient.Active ? 1 : 0),
                                                new SqlParameter("@ClientNote", hfedClient.ClientNote + ""),
                                                new SqlParameter("@Location_Id", hfedClient.Location.Id),
                                                new SqlParameter("@NumberInHousehold", hfedClient.NumberInHousehold));
         }
         // This version not updating location change:
         TempData ["ClientLocationId"] = hfedClient.Location.Id;
         return(RedirectToAction("Index"));
     }
     return(View(hfedClient));
 }
Ejemplo n.º 4
0
        // GET: HfedClients/Create
        public ActionResult Create()
        {
            var hfedClientView = new HfedClient
            {
                HfedLocations = db.HfedLocations.OrderBy(l => l.Name).ToList(), Active = true
            };

            return(View(hfedClientView));
        }
Ejemplo n.º 5
0
        public ActionResult Edit([Bind(Include = "Id,FirstName,LastName,DateOfBirth,Active,Location,ClientNote")] HfedClient hfedClient)
        {
            if (ModelState.IsValid)
            {
                using (var context = new SenecaContext())
                {
                    var sqlString = "UPDATE HfedClient SET ";
                    if (hfedClient.FirstName != null)
                    {
                        sqlString += "FirstName = '" + hfedClient.FirstName + "',";
                    }

                    if (hfedClient.LastName != null)
                    {
                        sqlString += "LastName = '" + hfedClient.LastName + "',";
                    }

                    sqlString += "DateOfBirth = '" + hfedClient.DateOfBirth + "',";

                    if (hfedClient.Active)
                    {
                        sqlString += "Active = 1,";
                    }
                    else
                    {
                        sqlString += "Active = 0,";
                    }

                    if (hfedClient.ClientNote != null)
                    {
                        sqlString += "ClientNote = '" + hfedClient.ClientNote.Replace("'", "''") + "',";
                    }
                    else
                    {
                        sqlString += "ClientNote='',";
                    }

                    sqlString += "Location_Id = " + hfedClient.Location.Id;
                    sqlString += " WHERE Id = " + hfedClient.Id;
                    context.Database.ExecuteSqlCommand(sqlString);
                }
                // This version not updating location change:
                //db.Entry(hfedClient).State = EntityState.Modified;
                //db.SaveChanges();

                TempData ["ClientLocationId"] = hfedClient.Location.Id;
                return(RedirectToAction("Index"));
            }
            return(View(hfedClient));
        }
Ejemplo n.º 6
0
        // GET: HfedClients/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            HfedClient hfedClient = db.HfedClients.Find(id);

            if (hfedClient == null)
            {
                return(HttpNotFound());
            }

            hfedClient.HfedLocations = db.HfedLocations.OrderBy(l => l.Name).ToList();
            return(View(hfedClient));
        }
Ejemplo n.º 7
0
        public ActionResult Create([Bind(Include = "Id,FirstName,LastName,DateOfBirth,Active,ClientNote,Location,NumberInHousehold")] HfedClient hfedClient)
        {
            //EF adding blank Foreign Key records: use raw SQL
            using (var context = new SenecaContext())
            {
                var query = @"INSERT INTO HfedClient"
                            + " (FirstName,LastName,DateOfBirth,Active,ClientNote,Location_Id,NumberInHousehold)"
                            + " VALUES "
                            + "(@FirstName,@LastName,@DateOfBirth,@Active,@ClientNote,@Location_Id,@NumberInHousehold)";

                context.Database.ExecuteSqlCommand(query,
                                                   new SqlParameter("@FirstName", hfedClient.FirstName),
                                                   new SqlParameter("@LastName", hfedClient.LastName),
                                                   new SqlParameter("@DateOfBirth", hfedClient.DateOfBirth.ToShortDateString()),
                                                   new SqlParameter("@Active", hfedClient.Active ? 1 : 0),
                                                   new SqlParameter("@ClientNote", hfedClient.ClientNote + ""),
                                                   new SqlParameter("@Location_Id", hfedClient.Location.Id),
                                                   new SqlParameter("@NumberInHousehold", hfedClient.NumberInHousehold));
            }
            // This version not updating location change:
            TempData["ClientLocationId"] = hfedClient.Location.Id;
            return(RedirectToAction("Index"));
        }