private void PopulateClientData() { using (var person = new FlexSQL()) { var localId = Engine.QueueOfRfids.Dequeue(); var currentGuy = from guy in person.tblPersoner where guy.rfid.Equals(localId) select guy; clientData.ForName = (from name in currentGuy where name.ForName != null select name.ForName).Single(); clientData.Country = (from country in currentGuy where country.Land != null select country.Land).Single(); clientData.UserName = (from userName in currentGuy where userName.UserNamn != null select userName.UserNamn).Single(); Engine.UserNames.Add(clientData.UserName); } using (var timeCard = new FlexSQL()) { // this is ok, its either in or out. clientData.ActivityType = (from type in timeCard.tidKort where type.aktivitet != null select type.aktivitet).First(); //clientData.ActivityDateStamp = DateTime.Parse((from dateStamp in timeCard.tidKort where dateStamp.Datum != null select dateStamp).ToString()); var dateList = (from dateStamp in timeCard.tidKort where dateStamp.Datum != null && dateStamp.UserNamn == clientData.UserName select dateStamp.Datum).ToList(); var lastDate = dateList.Last(); clientData.ActivityDateStamp = DateTime.Parse(lastDate); clientData.ActivityTimeStamp = DateTime.Parse((from timeStamp in timeCard.tidKort where timeStamp.tidStempel != null select timeStamp.tidStempel).First()); // ^ this is the actual timestamp of the specific event of the day. //todo: On release to live, change to DateTime.Now();.... ON FIELD TEST! Sooon var currenttime = new DateTime(DateTime.Today.Year, 06, 26, 12, 0, 00).ToString("d", CultureInfo.CreateSpecificCulture("sv-SE")); //placeholder for "todays" date and time var temp = (from comment in timeCard.tidKort where comment.UserNamn == clientData.UserName && comment.aktivitet != "in" && comment.Datum == currenttime select comment.kommentar).ToList(); var lastComment = temp.Last(); clientData.ActivityComment = lastComment; } }
public void SaveToDatabase() { // time to put data in the database! Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("sv-SE"); //clientData.ActivityType // into database tblTidKort var timeTable = new tidKort { aktivitet = clientData.ActivityType, Datum = DateTime.Now.ToString("d"), UserNamn = clientData.UserName, kommentar = clientData.ActivityComment, tidStempel = DateTime.Now.ToShortTimeString() }; using (var dbContext = new FlexSQL() ) { dbContext.Entry(timeTable).State = EntityState.Added; dbContext.SaveChanges(); } }