Example #1
0
        /// <summary>
        /// Add Tenets to an appartment
        /// </summary>
        /// <param name="name">name of the tennet Firstname Lastname</param>
        /// <param name="locationName">Apparent to add the tenent to</param>
        /// <returns>true if succsefull. false if unseccesfull</returns>
        public static bool AddTenant(string name, string locationName)
        {
            try
            {
                using (var dataList = new Database.HFABDataList())
                {
                    var nameSplit = name.Split(" ");

                    const string tagList        = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
                    var          tagListArray   = tagList.ToCharArray();
                    var          i              = 0;
                    var          emptyTagLetter = false;
                    while ((i < tagListArray.Length) && (!emptyTagLetter))
                    {
                        var tagToCheck = locationName + tagListArray[i];
                        var reslult    = dataList.Persons.Any(t => t.Tag == tagToCheck);
                        if (!reslult)
                        {
                            var location = dataList.Locations.FirstOrDefault(l => l.Name == locationName);
                            emptyTagLetter = true;
                            dataList.Persons.Add(new Models.Person {
                                FirstName = nameSplit[0], LastName = nameSplit[1], Tag = tagToCheck, Location = location
                            });
                            dataList.SaveChanges();
                        }
                        i++;
                    }
                }
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Example #2
0
        /// <summary>
        /// Remove and tenet or Update
        /// </summary>
        /// <param name="tenant">Tag or Firstname Lastname</param>
        /// <param name="locationName">Optional Apartment to move to</param>
        /// <returns>true if succsefull. false if unseccesfull</returns>
        public static bool MoveTenant(string tenant, string locationName = null)
        {
            try
            {
                using (var dataList = new Database.HFABDataList())
                {
                    var person = dataList.Persons.Include("Location").FirstOrDefault(t => t.Tag == tenant || t.FirstName + " " + t.LastName == tenant);
                    if (String.IsNullOrEmpty(locationName))
                    {
                        person.Location = null;
                        person.Tag      = null;
                        dataList.SaveChanges();
                    }
                    else
                    {
                        const string tagList        = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
                        var          tagListArray   = tagList.ToCharArray();
                        var          i              = 0;
                        var          emptyTagLetter = false;
                        while ((i < tagListArray.Length) && (!emptyTagLetter))
                        {
                            var tagToCheck = locationName + tagListArray[i];
                            var reslult    = dataList.Persons.Any(p => p.Tag == tagToCheck);
                            if (!reslult)
                            {
                                var location = dataList.Locations.FirstOrDefault(l => l.Name == locationName);
                                emptyTagLetter  = true;
                                person.Tag      = tagToCheck;
                                person.Location = location;
                                dataList.SaveChanges();
                            }
                            i++;
                        }
                    }
                }

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Example #3
0
 /// <summary>
 /// Enter Log to db
 /// </summary>
 /// <param name="date"></param>
 /// <param name="doorName"></param>
 /// <param name="codeName"></param>
 /// <param name="tagName"></param>
 /// <returns>true if succsefull. false if unseccesfull</returns>
 public static bool LogEntry(string date, string doorName, string codeName, string tagName)
 {
     try
     {
         using (var dataList = new Database.HFABDataList())
         {
             var door   = dataList.DoorNames.FirstOrDefault(d => d.Name == doorName.ToUpper());
             var @event = dataList.Events.FirstOrDefault(d => d.Code == codeName.ToUpper());
             var person = dataList.Persons.FirstOrDefault(d => d.Tag == tagName.ToUpper());
             dataList.Loggs.Add(new Models.Logg {
                 Date = date, Door = door, Event = @event, Person = person
             });
             dataList.SaveChanges();
         }
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }