public ActionResult Family( string data ) { if( !Auth() ) return CheckInMessage.createErrorReturn( "Authentication failed, please try again", CheckInMessage.API_ERROR_INVALID_CREDENTIALS ); CheckInMessage dataIn = CheckInMessage.createFromString( data ); CheckInFamilySearch cfs = JsonConvert.DeserializeObject<CheckInFamilySearch>( dataIn.data ); DbUtil.LogActivity( "Check-In Family: " + cfs.familyID ); CheckInMessage br = new CheckInMessage(); br.setNoError(); int tzOffset = DbUtil.Db.Setting( "TZOffset", "0" ).ToInt(); List<CheckInFamily> families = new List<CheckInFamily>(); FamilyCheckinLock familyLock = DbUtil.Db.FamilyCheckinLocks.SingleOrDefault( f => f.FamilyId == dataIn.argInt ); CheckInFamily family = new CheckInFamily( cfs.familyID, "", familyLock?.Locked ?? false ); List<CheckinFamilyMember> members = (from a in DbUtil.Db.CheckinFamilyMembers( cfs.familyID, cfs.campus, cfs.day ).ToList() orderby a.Position, a.Position == 10 ? a.Genderid : 10, a.Age descending, a.Hour select a).ToList(); foreach( CheckinFamilyMember member in members ) { family.addMember( member, cfs.day, tzOffset ); } families.Add( family ); br.count = 1; br.data = SerializeJSON( families, dataIn.version ); return br; }
public ActionResult JoinOrg( string data ) { if( !Auth() ) return CheckInMessage.createErrorReturn( "Authentication failed, please try again", CheckInMessage.API_ERROR_INVALID_CREDENTIALS ); CheckInMessage dataIn = CheckInMessage.createFromString( data ); CheckInJoinOrg cjo = JsonConvert.DeserializeObject<CheckInJoinOrg>( dataIn.data ); OrganizationMember om = DbUtil.Db.OrganizationMembers.SingleOrDefault( m => m.PeopleId == cjo.peopleID && m.OrganizationId == cjo.orgID ); if( om == null && cjo.join ) om = OrganizationMember.InsertOrgMembers( DbUtil.Db, cjo.orgID, cjo.peopleID, MemberTypeCode.Member, DateTime.Today ); if( om != null && !cjo.join ) { om.Drop( DbUtil.Db, DateTime.Now ); DbUtil.LogActivity( $"Dropped {om.PeopleId} for {om.Organization.OrganizationId} via {dataIn.getSourceOS()} app", peopleid: om.PeopleId, orgid: om.OrganizationId ); } DbUtil.Db.SubmitChanges(); // Check Entry Point and replace if Check-In Person person = DbUtil.Db.People.FirstOrDefault( p => p.PeopleId == cjo.peopleID ); if( person?.EntryPoint != null && person.EntryPoint.Code == "CHECKIN" && om != null ) { person.EntryPoint = om.Organization.EntryPoint; DbUtil.Db.SubmitChanges(); } CheckInMessage br = new CheckInMessage(); br.setNoError(); br.count = 1; return br; }
public ActionResult FetchPerson( string data ) { // Authenticate first if( !Auth() ) return CheckInMessage.createErrorReturn( "Authentication failed, please try again", CheckInMessage.API_ERROR_INVALID_CREDENTIALS ); CheckInMessage dataIn = CheckInMessage.createFromString( data ); CheckInMessage br = new CheckInMessage(); Person person = DbUtil.Db.People.SingleOrDefault( p => p.PeopleId == dataIn.argInt ); if( person == null ) { br.setError( CheckInMessage.API_ERROR_PERSON_NOT_FOUND ); br.data = "Person not found."; return br; } br.setNoError(); br.count = 1; if( dataIn.device == CheckInMessage.API_DEVICE_ANDROID ) { br.data = SerializeJSON( new CheckInPerson().populate( person ), dataIn.version ); } else { List<CheckInPerson> mp = new List<CheckInPerson> {new CheckInPerson().populate( person )}; br.data = SerializeJSON( mp, dataIn.version ); } return br; }
void ProcessClient(Bluetooth.BluetoothClient client) { var stream = client.GetStream(); while (true) { var buffer = new byte[Message.HeaderSize]; if (stream.Read(buffer, 0, Message.HeaderSize) > 0 && isRunning) { var message = new MessageInfo(buffer); switch (message.Type) { case MessageType.MoveScreen: case MessageType.MouseButton: case MessageType.MouseWheel: case MessageType.MouseMove: case MessageType.KeyPress: messages.Enqueue(message); break; case MessageType.Clipboard: messages.Enqueue(MessagePacket.Parse(message, stream)); break; case MessageType.CheckIn: CheckInMessage checkIn = new CheckInMessage(MessagePacket.Parse(message, stream)); ScreenConfig(stream); messages.Enqueue(checkIn); break; } messageHandle.Set(); } } }
public ActionResult LockFamily(string data) { if (!Auth()) { return(CheckInMessage.createErrorReturn("Authentication failed, please try again", CheckInMessage.API_ERROR_INVALID_CREDENTIALS)); } CheckInMessage dataIn = CheckInMessage.createFromString(data); FamilyCheckinLock lockf = CurrentDatabase.FamilyCheckinLocks.SingleOrDefault(f => f.FamilyId == dataIn.argInt); if (lockf == null) { lockf = new FamilyCheckinLock { FamilyId = dataIn.argInt, Created = DateTime.Now }; CurrentDatabase.FamilyCheckinLocks.InsertOnSubmit(lockf); } lockf.Locked = true; lockf.Created = DateTime.Now; CurrentDatabase.SubmitChanges(); CheckInMessage br = new CheckInMessage(); br.setNoError(); br.id = dataIn.argInt; return(br); }
public ActionResult FetchImage(string data) { // Authenticate first if (!Auth()) { return(CheckInMessage.createErrorReturn("Authentication failed, please try again", CheckInMessage.API_ERROR_INVALID_CREDENTIALS)); } CheckInMessage dataIn = CheckInMessage.createFromString(data); CheckInFetchImage cifi = JsonConvert.DeserializeObject <CheckInFetchImage>(dataIn.data); CheckInMessage br = new CheckInMessage(); if (cifi.id == 0) { return(br.setData("The ID for the person cannot be set to zero")); } br.data = "The picture was not found."; Person person = CurrentDatabase.People.SingleOrDefault(pp => pp.PeopleId == cifi.id); if (person == null || person.PictureId == null) { return(br); } Image image = null; switch (cifi.size) { case 0: // 50 x 50 image = CurrentImageDatabase.Images.SingleOrDefault(i => i.Id == person.Picture.ThumbId); break; case 1: // 120 x 120 image = CurrentImageDatabase.Images.SingleOrDefault(i => i.Id == person.Picture.SmallId); break; case 2: // 320 x 400 image = CurrentImageDatabase.Images.SingleOrDefault(i => i.Id == person.Picture.MediumId); break; case 3: // 570 x 800 image = CurrentImageDatabase.Images.SingleOrDefault(i => i.Id == person.Picture.LargeId); break; } if (image == null) { return(br); } br.data = Convert.ToBase64String(image.Bits); br.setNoError(); br.count = 1; return(br); }
public ActionResult DeleteConfirmed(int id) { CheckInMessage checkInMessage = db.CheckInMessages.Find(id); db.CheckInMessages.Remove(checkInMessage); db.SaveChanges(); return(RedirectToAction("Index")); }
async void ScreenConfig(System.IO.Stream stream) { var config = new CheckInMessage(state.ClientName, _screen.ScreenConfiguration[state.ClientName]); var buffer = config.GetBytes(); await stream.WriteAsync(buffer, 0, buffer.Length); await stream.FlushAsync(); }
public ActionResult ClassSearch( string data ) { if( !Auth() ) return CheckInMessage.createErrorReturn( "Authentication failed, please try again", CheckInMessage.API_ERROR_INVALID_CREDENTIALS ); CheckInMessage dataIn = CheckInMessage.createFromString( data ); CheckInClassSearch ccs = JsonConvert.DeserializeObject<CheckInClassSearch>( dataIn.data ); DbUtil.LogActivity( "Check-In Class Search: " + ccs.peopleID ); var person = (from p in DbUtil.Db.People where p.PeopleId == ccs.peopleID select new {p.FamilyId, p.BirthDate, p.Grade}).SingleOrDefault(); if( person == null ) return CheckInMessage.createErrorReturn( "Person not found", CheckInMessage.API_ERROR_PERSON_NOT_FOUND ); CheckInMessage br = new CheckInMessage(); br.setNoError(); List<CheckInOrganization> orgs = (from o in DbUtil.Db.Organizations let sc = o.OrgSchedules.FirstOrDefault() let meetingHours = DbUtil.Db.GetTodaysMeetingHours( o.OrganizationId, ccs.day ) let bdaystart = o.BirthDayStart ?? DateTime.MaxValue where (o.SuspendCheckin ?? false) == false || ccs.noAgeCheck where person.BirthDate == null || person.BirthDate <= o.BirthDayEnd || o.BirthDayEnd == null || ccs.noAgeCheck where person.BirthDate == null || person.BirthDate >= o.BirthDayStart || o.BirthDayStart == null || ccs.noAgeCheck where o.CanSelfCheckin == true where (o.ClassFilled ?? false) == false where (o.CampusId == null && o.AllowNonCampusCheckIn == true) || o.CampusId == ccs.campus || ccs.campus == 0 where o.OrganizationStatusId == OrgStatusCode.Active orderby sc.SchedTime.Value.TimeOfDay, bdaystart, o.OrganizationName from meeting in meetingHours select new CheckInOrganization() { id = o.OrganizationId, leader = o.LeaderName, name = o.OrganizationName, hour = meeting.Hour.Value, birthdayStart = o.BirthDayStart, birthdayEnd = o.BirthDayEnd, location = o.Location, allowOverlap = o.AllowAttendOverlap }).ToList(); // Add lead time adjustment for different timezones here int tzOffset = DbUtil.Db.Setting( "TZOffset", "0" ).ToInt(); foreach( CheckInOrganization org in orgs ) { org.adjustLeadTime( ccs.day, tzOffset ); } br.data = SerializeJSON( orgs, dataIn.version ); return br; }
public ActionResult Authenticate( string data ) { if( !Auth() ) return CheckInMessage.createErrorReturn( "Authentication failed, please try again", CheckInMessage.API_ERROR_INVALID_CREDENTIALS ); CheckInMessage br = new CheckInMessage(); br.setNoError(); br.data = JsonConvert.SerializeObject( new CheckInInformation( getSettings(), getCampuses(), getLabelFormats() ) ); return br; }
public ActionResult NameSearch( string data ) { if( !Auth() ) return CheckInMessage.createErrorReturn( "Authentication failed, please try again", CheckInMessage.API_ERROR_INVALID_CREDENTIALS ); CheckInMessage dataIn = CheckInMessage.createFromString( data ); CheckInNameSearch cns = JsonConvert.DeserializeObject<CheckInNameSearch>( dataIn.data ); cns.splitName(); DbUtil.LogActivity( "Check-In Name Search: " + cns.name ); IQueryable<Person> q = DbUtil.Db.People.Select( p => p ); if( cns.first.HasValue() ) { q = from p in q where (p.LastName.StartsWith( cns.last ) || p.MaidenName.StartsWith( cns.last )) && (p.FirstName.StartsWith( cns.first ) || p.NickName.StartsWith( cns.first ) || p.MiddleName.StartsWith( cns.first )) select p; } else { q = from p in q where p.LastName.StartsWith( cns.last ) || p.FirstName.StartsWith( cns.last ) || p.NickName.StartsWith( cns.last ) || p.MiddleName.StartsWith( cns.last ) select p; } List<CheckInPerson> q2 = (from p in q let recreg = p.RecRegs.FirstOrDefault() orderby p.Name2, p.PeopleId where p.DeceasedDate == null select new CheckInPerson { id = p.PeopleId, familyID = p.FamilyId, first = p.PreferredName, last = p.LastName, goesby = p.NickName, altName = p.AltName, cell = p.CellPhone, home = p.HomePhone, address = p.Family.AddressLineOne, age = p.Age ?? 0 }).Take( 200 ).ToList(); foreach( CheckInPerson person in q2 ) { person.loadImage(); } CheckInMessage br = new CheckInMessage(); br.setNoError(); br.count = q2.Count(); br.data = SerializeJSON( q2, dataIn.version ); return br; }
public ActionResult Edit([Bind(Include = "checkInMessageId,recipientCategoryId,recipientId,Location,introMessage,closingMessage,deadline")] CheckInMessage checkInMessage) { if (ModelState.IsValid) { db.Entry(checkInMessage).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.recipientId = new SelectList(db.Recipients, "recipientId", "nickName", checkInMessage.recipientId); ViewBag.recipientCategoryId = new SelectList(db.RecipientCategories, "recipientCategoryId", "categoryName", checkInMessage.recipientCategoryId); return(View(checkInMessage)); }
public ActionResult NumberSearch(string data) { if (!Auth()) { return(CheckInMessage.createErrorReturn("Authentication failed, please try again", CheckInMessage.API_ERROR_INVALID_CREDENTIALS)); } CheckInMessage dataIn = CheckInMessage.createFromString(data); CheckInNumberSearch cns = JsonConvert.DeserializeObject <CheckInNumberSearch>(dataIn.data); DbUtil.LogActivity("Check-In Number Search: " + cns.search); List <CheckinMatch> matches = CurrentDatabase.CheckinMatch(cns.search).ToList(); CheckInMessage br = new CheckInMessage(); br.setNoError(); int tzOffset = CurrentDatabase.Setting("TZOffset", "0").ToInt(); List <CheckInFamily> families = new List <CheckInFamily>(); if (matches.Count > 0) { foreach (CheckinMatch match in matches) { if (match.Familyid != null) { CheckInFamily family = new CheckInFamily(match.Familyid.Value, match.Name, match.Locked ?? false, CurrentDatabase, CurrentImageDatabase); List <CheckinFamilyMember> members = (from a in CurrentDatabase.CheckinFamilyMembers(match.Familyid, cns.campus, cns.day).ToList() orderby a.Position, a.Position == 10 ? a.Genderid : 10, a.Age descending, a.Hour select a).ToList(); foreach (CheckinFamilyMember member in members) { family.addMember(CurrentDatabase, CurrentImageDatabase, member, cns.day, tzOffset); } families.Add(family); br.count++; } } br.data = SerializeJSON(families, dataIn.version); } return(br); }
// GET: CheckInMessages/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CheckInMessage checkInMessage = db.CheckInMessages.Find(id); if (checkInMessage == null) { return(HttpNotFound()); } return(View(checkInMessage)); }
void ProcessClient(ISocketClient client) { var stream = client.GetStream(); while (isRunning) { var buffer = new byte[Message.HeaderSize]; if (stream.Read(buffer, 0, Message.HeaderSize) > 0 && isRunning) { switch ((MessageType)(buffer[0] & Message.TypeMask)) { case MessageType.MoveScreen: break; case MessageType.MouseWheel: OnMouseWheelFromServer(buffer); break; case MessageType.MouseButton: OnMouseButtonFromServer(buffer); break; case MessageType.MouseMove: OnMouseMoveFromServer(buffer); break; case MessageType.KeyPress: OnKeyPressFromServer(buffer); break; case MessageType.Clipboard: OnClipboardFromServer(new ClipboardMessage(MessagePacket.Parse(new MessageInfo(buffer), stream))); break; case MessageType.CheckIn: CheckInMessage checkIn = new CheckInMessage(MessagePacket.Parse(new MessageInfo(buffer), stream)); // Config OnScreenConfig(checkIn.Screens); ScreenConfig(stream); break; case MessageType.CheckOut: RemoveScreen(CheckOutMessage.Parse(new MessageInfo(buffer), stream)); client.Dispose(); return; } } } }
public ActionResult PrintLabels(string data) { if (!Auth()) { return(CheckInMessage.createErrorReturn("Authentication failed, please try again", CheckInMessage.API_ERROR_INVALID_CREDENTIALS)); } CheckInMessage dataIn = CheckInMessage.createFromString(data); List <CheckInPrintLabel> labels = JsonConvert.DeserializeObject <List <CheckInPrintLabel> >(dataIn.data); string securityCode = CurrentDatabase.NextSecurityCode().Select(c => c.Code).Single(); StringBuilder builder = new StringBuilder(); XmlWriter writer = XmlWriter.Create(builder); writer.WriteStartDocument(); writer.WriteStartElement("PrintJob"); writer.WriteElementString("securitycode", securityCode); writer.WriteStartElement("list"); foreach (CheckInPrintLabel label in labels) { label.writeToXML(writer, securityCode); } // list writer.WriteEndElement(); // PrintJob writer.WriteEndElement(); writer.Close(); PrintJob job = new PrintJob { Id = dataIn.argString, Data = builder.ToString(), Stamp = DateTime.Now }; CurrentDatabase.PrintJobs.InsertOnSubmit(job); CurrentDatabase.SubmitChanges(); CheckInMessage br = new CheckInMessage(); br.setNoError(); br.count = 1; return(br); }
public ActionResult FamilyInfo( string data ) { if( !Auth() ) return CheckInMessage.createErrorReturn( "Authentication failed, please try again", CheckInMessage.API_ERROR_INVALID_CREDENTIALS ); CheckInMessage dataIn = CheckInMessage.createFromString( data ); Family family = DbUtil.Db.Families.First( fam => fam.FamilyId == dataIn.argInt ); CheckInMessage br = new CheckInMessage(); br.setNoError(); br.count = 1; br.id = family.FamilyId; br.data = SerializeJSON( new CheckInFamilyInfo( family ), dataIn.version ); return br; }
// GET: CheckInMessages/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CheckInMessage checkInMessage = db.CheckInMessages.Find(id); if (checkInMessage == null) { return(HttpNotFound()); } ViewBag.recipientId = new SelectList(db.Recipients, "recipientId", "nickName", checkInMessage.recipientId); ViewBag.recipientCategoryId = new SelectList(db.RecipientCategories, "recipientCategoryId", "categoryName", checkInMessage.recipientCategoryId); return(View(checkInMessage)); }
public ActionResult UnLockFamily( string data ) { if( !Auth() ) return CheckInMessage.createErrorReturn( "Authentication failed, please try again", CheckInMessage.API_ERROR_INVALID_CREDENTIALS ); CheckInMessage dataIn = CheckInMessage.createFromString( data ); FamilyCheckinLock lockf = DbUtil.Db.FamilyCheckinLocks.SingleOrDefault( f => f.FamilyId == dataIn.argInt ); if( lockf != null ) { lockf.Locked = false; DbUtil.Db.SubmitChanges(); } CheckInMessage br = new CheckInMessage(); br.setNoError(); br.id = dataIn.argInt; return br; }
public ActionResult SaveSettings(string data) { if (!Auth()) { return(CheckInMessage.createErrorReturn("Authentication failed, please try again", CheckInMessage.API_ERROR_INVALID_CREDENTIALS)); } CheckInMessage dataIn = CheckInMessage.createFromString(data); CheckInSettingsEntry entry = JsonConvert.DeserializeObject <CheckInSettingsEntry>(dataIn.data); CheckInSetting setting = (from e in CurrentDatabase.CheckInSettings where e.Name == entry.name select e).SingleOrDefault(); CheckInMessage br = new CheckInMessage(); if (setting == null) { setting = new CheckInSetting { Name = entry.name, Settings = entry.settings }; CurrentDatabase.CheckInSettings.InsertOnSubmit(setting); br.data = "Settings saved"; } else { setting.Settings = entry.settings; br.data = "Settings updated"; } CurrentDatabase.SubmitChanges(); br.setNoError(); br.id = setting.Id; br.count = 1; return(br); }
public ActionResult RecordAttend(string data) { // Authenticate first if (!Auth()) { return(CheckInMessage.createErrorReturn("Authentication failed, please try again", CheckInMessage.API_ERROR_INVALID_CREDENTIALS)); } CheckInMessage dataIn = CheckInMessage.createFromString(data); CheckInAttend cia = JsonConvert.DeserializeObject <CheckInAttend>(dataIn.data); Meeting meeting = CurrentDatabase.Meetings.SingleOrDefault(m => m.OrganizationId == cia.orgID && m.MeetingDate == cia.datetime); if (meeting == null) { int meetingID = CurrentDatabase.CreateMeeting(cia.orgID, cia.datetime); meeting = CurrentDatabase.Meetings.SingleOrDefault(m => m.MeetingId == meetingID); } Attend.RecordAttend(CurrentDatabase, cia.peopleID, cia.orgID, cia.present, cia.datetime); CurrentDatabase.UpdateMeetingCounters(cia.orgID); DbUtil.LogActivity($"Check-In Record Attend Org ID:{cia.orgID} People ID:{cia.peopleID} User ID:{CurrentDatabase.UserPeopleId} Attended:{cia.present}"); // Check Entry Point and replace if Check-In Person person = CurrentDatabase.People.FirstOrDefault(p => p.PeopleId == cia.peopleID); if (person != null && person.EntryPoint != null && person.EntryPoint.Code != null && person.EntryPoint.Code == "CHECKIN" && meeting != null) { person.EntryPoint = meeting.Organization.EntryPoint; CurrentDatabase.SubmitChanges(); } CheckInMessage br = new CheckInMessage(); br.setNoError(); br.count = 1; return(br); }
public ActionResult AddEditPerson(string data) { // Authenticate first if (!Auth()) { return(CheckInMessage.createErrorReturn("Authentication failed, please try again", CheckInMessage.API_ERROR_INVALID_CREDENTIALS)); } CheckInMessage dataIn = CheckInMessage.createFromString(data); CheckInAddEditPerson aep = JsonConvert.DeserializeObject <CheckInAddEditPerson>(dataIn.data); aep.clean(); CheckInAddEditPersonResults results = new CheckInAddEditPersonResults(); Family f; Person p; if (aep.edit) { p = CurrentDatabase.LoadPersonById(aep.id); f = CurrentDatabase.Families.First(fam => fam.FamilyId == p.FamilyId); f.HomePhone = aep.homePhone; f.AddressLineOne = aep.address; f.AddressLineTwo = aep.address2; f.CityName = aep.city; f.StateCode = aep.state; f.ZipCode = aep.zipcode; f.CountryName = aep.country; } else { results.newPerson = true; p = new Person { CreatedDate = Util.Now, CreatedBy = CurrentDatabase.UserId, MemberStatusId = MemberStatusCode.JustAdded, AddressTypeId = 10, OriginId = OriginCode.Visit, EntryPoint = getCheckInEntryPointID() }; if (aep.campus > 0) { p.CampusId = aep.campus; } p.Name = ""; if (aep.familyID > 0) { f = CurrentDatabase.Families.First(fam => fam.FamilyId == aep.familyID); } else { results.newFamily = true; f = new Family(); CurrentDatabase.Families.InsertOnSubmit(f); } f.HomePhone = aep.homePhone; f.AddressLineOne = aep.address; f.AddressLineTwo = aep.address2; f.CityName = aep.city; f.StateCode = aep.state; f.ZipCode = aep.zipcode; f.CountryName = aep.country; f.People.Add(p); p.PositionInFamilyId = CurrentDatabase.ComputePositionInFamily(aep.getAge(), aep.maritalStatusID == MaritalStatusCode.Married, f.FamilyId) ?? PositionInFamily.PrimaryAdult; } p.FirstName = aep.firstName; p.LastName = aep.lastName; p.NickName = aep.goesBy; p.AltName = aep.altName; if (dataIn.version >= CheckInMessage.API_V3) { p.SetRecReg().Fname = aep.father; p.SetRecReg().Mname = aep.mother; } // Check-In API Version 2 or greater adds the ability to clear the birthday if (dataIn.version >= CheckInMessage.API_V2) { if (aep.birthdaySet && aep.birthday != null) { p.BirthDay = aep.birthday.Value.Day; p.BirthMonth = aep.birthday.Value.Month; p.BirthYear = aep.birthday.Value.Year; } else { if (aep.birthdayClear) { p.BirthDay = null; p.BirthMonth = null; p.BirthYear = null; } } } else { if (aep.birthday != null) { p.BirthDay = aep.birthday.Value.Day; p.BirthMonth = aep.birthday.Value.Month; p.BirthYear = aep.birthday.Value.Year; } } p.GenderId = aep.genderID; p.MaritalStatusId = aep.maritalStatusID; p.FixTitle(); p.EmailAddress = aep.eMail; p.CellPhone = aep.cellPhone; p.HomePhone = aep.homePhone; p.SetRecReg().MedicalDescription = aep.allergies; p.SetRecReg().Emcontact = aep.emergencyName; p.SetRecReg().Emphone = aep.emergencyPhone.Truncate(50); p.SetRecReg().ActiveInAnotherChurch = !string.IsNullOrEmpty(aep.church); p.OtherPreviousChurch = aep.church; CurrentDatabase.SubmitChanges(); results.familyID = f.FamilyId; results.peopleID = p.PeopleId; results.position = p.PositionInFamilyId; CheckInMessage br = new CheckInMessage(); br.setNoError(); br.count = 1; br.data = SerializeJSON(results, dataIn.version); return(br); }
public ActionResult SaveImage( string data ) { // Authenticate first if( !Auth() ) return CheckInMessage.createErrorReturn( "Authentication failed, please try again", CheckInMessage.API_ERROR_INVALID_CREDENTIALS ); CheckInMessage dataIn = CheckInMessage.createFromString( data ); CheckInSaveImage cisi = JsonConvert.DeserializeObject<CheckInSaveImage>( dataIn.data ); CheckInMessage br = new CheckInMessage(); byte[] imageBytes = Convert.FromBase64String( cisi.image ); Person person = DbUtil.Db.People.SingleOrDefault( pp => pp.PeopleId == cisi.id ); if( person != null && person.Picture != null ) { // Thumb image Image imageDataThumb = ImageData.DbUtil.Db.Images.SingleOrDefault( i => i.Id == person.Picture.ThumbId ); if( imageDataThumb != null ) ImageData.DbUtil.Db.Images.DeleteOnSubmit( imageDataThumb ); // Small image Image imageDataSmall = ImageData.DbUtil.Db.Images.SingleOrDefault( i => i.Id == person.Picture.SmallId ); if( imageDataSmall != null ) ImageData.DbUtil.Db.Images.DeleteOnSubmit( imageDataSmall ); // Medium image Image imageDataMedium = ImageData.DbUtil.Db.Images.SingleOrDefault( i => i.Id == person.Picture.MediumId ); if( imageDataMedium != null ) ImageData.DbUtil.Db.Images.DeleteOnSubmit( imageDataMedium ); // Large image Image imageDataLarge = ImageData.DbUtil.Db.Images.SingleOrDefault( i => i.Id == person.Picture.LargeId ); if( imageDataLarge != null ) ImageData.DbUtil.Db.Images.DeleteOnSubmit( imageDataLarge ); person.Picture.ThumbId = Image.NewImageFromBits( imageBytes, 50, 50 ).Id; person.Picture.SmallId = Image.NewImageFromBits( imageBytes, 120, 120 ).Id; person.Picture.MediumId = Image.NewImageFromBits( imageBytes, 320, 400 ).Id; person.Picture.LargeId = Image.NewImageFromBits( imageBytes ).Id; } else { Picture newPicture = new Picture { ThumbId = Image.NewImageFromBits( imageBytes, 50, 50 ).Id, SmallId = Image.NewImageFromBits( imageBytes, 120, 120 ).Id, MediumId = Image.NewImageFromBits( imageBytes, 320, 400 ).Id, LargeId = Image.NewImageFromBits( imageBytes ).Id }; if( person != null ) person.Picture = newPicture; } person?.LogPictureUpload( DbUtil.Db, Util.UserPeopleId ?? 1 ); DbUtil.Db.SubmitChanges(); br.setNoError(); br.data = "Image updated"; br.id = cisi.id; br.count = 1; return br; }
public ActionResult SaveFamilyImage(string data) { // Authenticate first if (!Auth()) { return(CheckInMessage.createErrorReturn("Authentication failed, please try again", CheckInMessage.API_ERROR_INVALID_CREDENTIALS)); } CheckInMessage dataIn = CheckInMessage.createFromString(data); CheckInSaveImage cisi = JsonConvert.DeserializeObject <CheckInSaveImage>(dataIn.data); CheckInMessage br = new CheckInMessage(); byte[] imageBytes = Convert.FromBase64String(cisi.image); Family family = CurrentDatabase.Families.SingleOrDefault(pp => pp.FamilyId == cisi.id); if (family != null && family.Picture != null) { // Thumb image Image imageDataThumb = CurrentImageDatabase.Images.SingleOrDefault(i => i.Id == family.Picture.ThumbId); if (imageDataThumb != null) { CurrentImageDatabase.Images.DeleteOnSubmit(imageDataThumb); } // Small image Image imageDataSmall = CurrentImageDatabase.Images.SingleOrDefault(i => i.Id == family.Picture.SmallId); if (imageDataSmall != null) { CurrentImageDatabase.Images.DeleteOnSubmit(imageDataSmall); } // Medium image Image imageDataMedium = CurrentImageDatabase.Images.SingleOrDefault(i => i.Id == family.Picture.MediumId); if (imageDataMedium != null) { CurrentImageDatabase.Images.DeleteOnSubmit(imageDataMedium); } // Large image Image imageDataLarge = CurrentImageDatabase.Images.SingleOrDefault(i => i.Id == family.Picture.LargeId); if (imageDataLarge != null) { CurrentImageDatabase.Images.DeleteOnSubmit(imageDataLarge); } family.Picture.ThumbId = Image.NewImageFromBits(imageBytes, 50, 50, CurrentImageDatabase).Id; family.Picture.SmallId = Image.NewImageFromBits(imageBytes, 120, 120, CurrentImageDatabase).Id; family.Picture.MediumId = Image.NewImageFromBits(imageBytes, 320, 400, CurrentImageDatabase).Id; family.Picture.LargeId = Image.NewImageFromBits(imageBytes, CurrentImageDatabase).Id; } else { Picture newPicture = new Picture { ThumbId = Image.NewImageFromBits(imageBytes, 50, 50, CurrentImageDatabase).Id, SmallId = Image.NewImageFromBits(imageBytes, 120, 120, CurrentImageDatabase).Id, MediumId = Image.NewImageFromBits(imageBytes, 320, 400, CurrentImageDatabase).Id, LargeId = Image.NewImageFromBits(imageBytes, CurrentImageDatabase).Id }; if (family != null) { family.Picture = newPicture; } } CurrentDatabase.SubmitChanges(); br.setNoError(); br.data = "Image updated."; br.id = cisi.id; br.count = 1; return(br); }
/// <summary> /// Enforces the strict location threshold by removing attendances that would have ended up going into full location+schedules. /// Note: The is also checked earlier in the check-in process, so this catches ones that might have just gotten full in the last few seconds. /// </summary> /// <param name="action">The action.</param> /// <param name="checkInState">State of the check in.</param> /// <param name="attendanceService">The attendance service.</param> /// <param name="currentOccurrences">The current occurrences.</param> /// <param name="person">The person.</param> /// <param name="group">The group.</param> /// <param name="location">The location.</param> /// <param name="schedule">The schedule.</param> /// <param name="startDateTime">The start date time.</param> private void EnforceStrictLocationThreshold(WorkflowAction action, CheckInState checkInState, AttendanceService attendanceService, List <OccurrenceRecord> currentOccurrences, CheckInPerson person, CheckInGroup group, CheckInLocation location, CheckInSchedule schedule, DateTime startDateTime) { var thresHold = location.Location.SoftRoomThreshold.Value; if (checkInState.ManagerLoggedIn && location.Location.FirmRoomThreshold.HasValue && location.Location.FirmRoomThreshold.Value > location.Location.SoftRoomThreshold.Value) { thresHold = location.Location.FirmRoomThreshold.Value; } var currentOccurrence = GetCurrentOccurrence(currentOccurrences, location, schedule, startDateTime.Date); // The totalAttended is the number of people still checked in (not people who have been checked-out) // not counting the current person who may already be checked in, // + the number of people we have checked in so far (but haven't been saved yet). var attendanceQry = attendanceService.GetByDateOnLocationAndSchedule(startDateTime.Date, location.Location.Id, schedule.Schedule.Id) .AsNoTracking() .Where(a => a.EndDateTime == null); // Only process if the current person is NOT already checked-in to this location and schedule if (!attendanceQry.Where(a => a.PersonAlias.PersonId == person.Person.Id).Any()) { var totalAttended = attendanceQry.Count() + (currentOccurrence == null ? 0 : currentOccurrence.Count); // If over capacity, remove the schedule and add a warning message. if (totalAttended >= thresHold) { // Remove the schedule since the location was full for this schedule. location.Schedules.Remove(schedule); var message = new CheckInMessage() { MessageType = MessageType.Warning }; var mergeFields = Lava.LavaHelper.GetCommonMergeFields(null); mergeFields.Add(MergeFieldKey.Person, person.Person); mergeFields.Add(MergeFieldKey.Group, group.Group); mergeFields.Add(MergeFieldKey.Location, location.Location); mergeFields.Add(MergeFieldKey.Schedule, schedule.Schedule); message.MessageText = GetAttributeValue(action, AttributeKey.NotCheckedInMessageFormat).ResolveMergeFields(mergeFields); // Now add it to the check-in state message list for others to see. checkInState.Messages.Add(message); return; } else { // Keep track of anyone who was checked in so far. if (currentOccurrence == null) { currentOccurrence = new OccurrenceRecord() { Date = startDateTime.Date, LocationId = location.Location.Id, ScheduleId = schedule.Schedule.Id }; currentOccurrences.Add(currentOccurrence); } currentOccurrence.Count += 1; } } }
public ActionResult Upload(string data) { CheckScanAuthentication authentication = new CheckScanAuthentication(); authentication.authenticate(); if (authentication.hasError()) { return(CheckScanMessage.createLoginErrorReturn(authentication)); } User user = authentication.getUser(); if (!user.InRole("Finance")) { return(CheckScanMessage.createErrorReturn("Finance role is required for check scanning")); } CheckInMessage message = CheckInMessage.createFromString(data); List <CheckScanEntry> entries = JsonConvert.DeserializeObject <List <CheckScanEntry> >(message.data); BundleHeader header; if (message.id == 0) { header = new BundleHeader { BundleHeaderTypeId = 1, BundleStatusId = BundleStatusCode.Open, CreatedBy = user.UserId, ContributionDate = DateTime.Now, CreatedDate = DateTime.Now, FundId = CurrentDatabase.Setting("DefaultFundId", "1").ToInt(), RecordStatus = false, TotalCash = 0, TotalChecks = 0, TotalEnvelopes = 0, BundleTotal = 0 }; CurrentDatabase.BundleHeaders.InsertOnSubmit(header); CurrentDatabase.SubmitChanges(); } else { header = (from h in CurrentDatabase.BundleHeaders where h.BundleHeaderId == message.id select h).FirstOrDefault(); } CheckScanMessage response = new CheckScanMessage(); if (header != null) { foreach (CheckScanEntry entry in entries) { Other other = new Other(); other.Created = DateTime.Now; other.UserID = user.UserId; if (entry.front.Length > 0) { other.First = Convert.FromBase64String(entry.front); } if (entry.back.Length > 0) { other.Second = Convert.FromBase64String(entry.back); } CurrentImageDatabase.Others.InsertOnSubmit(other); CurrentImageDatabase.SubmitChanges(); var detail = new BundleDetail { BundleHeaderId = header.BundleHeaderId, CreatedBy = user.UserId, CreatedDate = DateTime.Now }; string bankAccount = entry.routing.Length > 0 && entry.account.Length > 0 ? Util.Encrypt(entry.routing + "|" + entry.account) : ""; detail.Contribution = new Contribution { CreatedBy = user.UserId, CreatedDate = detail.CreatedDate, FundId = header.FundId ?? 0, PeopleId = FindPerson(CurrentDatabase, entry.routing, entry.account), ContributionDate = header.ContributionDate, ContributionAmount = decimal.Parse(entry.amount), ContributionStatusId = 0, ContributionTypeId = 1, ContributionDesc = entry.notes, CheckNo = entry.number, BankAccount = bankAccount, ImageID = other.Id }; header.BundleDetails.Add(detail); CurrentDatabase.SubmitChanges(); } response.setSuccess(); response.id = header.BundleHeaderId; } else { response.setError(1, "Invalid Bundle ID"); } return(response); }
public ActionResult Create([Bind(Include = "checkInMessageId,recipientCategoryId,recipientId,Location,introMessage,closingMessage,deadline")] CheckInMessage model) { if (ModelState.IsValid) { //hard-coding some data to test email sending functionality model.closingMessage = "bye"; model.introMessage = "hi"; model.deadline = DateTime.Today; model.Location = "Madrid"; model.planDate = DateTime.Today; Recipient testingRecipient = new Recipient(); model.Recipient = testingRecipient; model.Recipient.recipientId = 1; model.Recipient.emailAddress = "*****@*****.**"; model.Recipient.UserEmail = "ian.stew12 @gmail.com"; model.Recipient.nickName = "LilRecipient"; db.CheckInMessages.Add(model); db.SaveChanges(); var emailViewModel = new CheckInEmailViewModel() { planDate = model.planDate, introMessage = model.introMessage, closingMessage = model.closingMessage, Location = model.Location }; if (model.RecipientCategory != null) { var recipientsInCategory = from recipient in db.Recipients where recipient.recipientCategoryId == model.recipientCategoryId select recipient; foreach (var recipient in recipientsInCategory) { emailViewModel.recipients.Add(recipient); } } else { var singleRecipient = testingRecipient; //delete after = to undo hard-coding //from recipient in db.Recipients //where recipient.UserEmail == model.Recipient.UserEmail //select recipient; emailViewModel.recipients = new List <Recipient>(); emailViewModel.recipients.Add(singleRecipient);//.FirstOrDefault()); } for (int i = 0; i < emailViewModel.recipients.Count; i++) { var email = new CheckInEmail() { recipient = emailViewModel.recipients[i], planDate = model.planDate, introMessage = model.introMessage, closingMessage = model.closingMessage, Location = model.Location, deadline = model.deadline }; //var jobId = BackgroundJob.Schedule(() => email.Send(), (email.deadline - DateTime.Now)); email.Send(); } return(RedirectToAction("Index")); } ViewBag.recipientId = new SelectList(db.Recipients, "recipientId", "nickName", model.recipientId); ViewBag.recipientCategoryId = new SelectList(db.RecipientCategories, "recipientCategoryId", "categoryName", model.recipientCategoryId); return(View(model)); }
/// <summary> /// Executes the specified workflow. /// </summary> /// <param name="rockContext">The rock context.</param> /// <param name="action">The workflow action.</param> /// <param name="entity">The entity.</param> /// <param name="errorMessages">The error messages.</param> /// <returns></returns> /// <exception cref="System.NotImplementedException"></exception> public override bool Execute(RockContext rockContext, Model.WorkflowAction action, Object entity, out List <string> errorMessages) { var checkInState = GetCheckInState(entity, out errorMessages); if (checkInState != null) { AttendanceCode attendanceCode = null; bool reuseCodeForFamily = checkInState.CheckInType != null && checkInState.CheckInType.ReuseSameCode; int securityCodeAlphaNumericLength = checkInState.CheckInType != null ? checkInState.CheckInType.SecurityCodeAlphaNumericLength : 3; int securityCodeAlphaLength = checkInState.CheckInType != null ? checkInState.CheckInType.SecurityCodeAlphaLength : 0; int securityCodeNumericLength = checkInState.CheckInType != null ? checkInState.CheckInType.SecurityCodeNumericLength : 0; bool securityCodeNumericRandom = checkInState.CheckInType != null ? checkInState.CheckInType.SecurityCodeNumericRandom : true; var attendanceCodeService = new AttendanceCodeService(rockContext); var attendanceService = new AttendanceService(rockContext); var groupMemberService = new GroupMemberService(rockContext); var personAliasService = new PersonAliasService(rockContext); var attendanceRecords = new List <Attendance>(); checkInState.Messages.Clear(); var family = checkInState.CheckIn.CurrentFamily; if (family != null) { var currentOccurences = new List <OccurenceRecord>(); foreach (var person in family.GetPeople(true)) { if (reuseCodeForFamily && attendanceCode != null) { person.SecurityCode = attendanceCode.Code; } else { attendanceCode = AttendanceCodeService.GetNew(securityCodeAlphaNumericLength, securityCodeAlphaLength, securityCodeNumericLength, securityCodeNumericRandom); person.SecurityCode = attendanceCode.Code; } foreach (var groupType in person.GetGroupTypes(true)) { foreach (var group in groupType.GetGroups(true)) { if (groupType.GroupType.AttendanceRule == AttendanceRule.AddOnCheckIn && groupType.GroupType.DefaultGroupRoleId.HasValue && !groupMemberService.GetByGroupIdAndPersonId(group.Group.Id, person.Person.Id, true).Any()) { var groupMember = new GroupMember(); groupMember.GroupId = group.Group.Id; groupMember.PersonId = person.Person.Id; groupMember.GroupRoleId = groupType.GroupType.DefaultGroupRoleId.Value; groupMemberService.Add(groupMember); } foreach (var location in group.GetLocations(true)) { bool isCheckedIntoLocation = false; foreach (var schedule in location.GetSchedules(true)) { var startDateTime = schedule.CampusCurrentDateTime; // If we're enforcing strict location thresholds, then before we create an attendance record // we need to check the location-schedule's current count. if (GetAttributeValue(action, "EnforceStrictLocationThreshold").AsBoolean() && location.Location.SoftRoomThreshold.HasValue) { var thresHold = location.Location.SoftRoomThreshold.Value; if (checkInState.ManagerLoggedIn && location.Location.FirmRoomThreshold.HasValue && location.Location.FirmRoomThreshold.Value > location.Location.SoftRoomThreshold.Value) { thresHold = location.Location.FirmRoomThreshold.Value; } var currentOccurence = GetCurrentOccurence(currentOccurences, location, schedule, startDateTime.Date); // The totalAttended is the number of people still checked in (not people who have been checked-out) // not counting the current person who may already be checked in, // + the number of people we have checked in so far (but haven't been saved yet). var attendanceQry = attendanceService.GetByDateOnLocationAndSchedule(startDateTime.Date, location.Location.Id, schedule.Schedule.Id) .AsNoTracking() .Where(a => a.EndDateTime == null); // Only process if the current person is NOT already checked-in to this location and schedule if (!attendanceQry.Where(a => a.PersonAlias.PersonId == person.Person.Id).Any()) { var totalAttended = attendanceQry.Count() + (currentOccurence == null ? 0 : currentOccurence.Count); // If over capacity, remove the schedule and add a warning message. if (totalAttended >= thresHold) { // Remove the schedule since the location was full for this schedule. location.Schedules.Remove(schedule); var message = new CheckInMessage() { MessageType = MessageType.Warning }; var mergeFields = Lava.LavaHelper.GetCommonMergeFields(null); mergeFields.Add("Person", person.Person); mergeFields.Add("Group", group.Group); mergeFields.Add("Location", location.Location); mergeFields.Add("Schedule", schedule.Schedule); message.MessageText = GetAttributeValue(action, "NotChecked-InMessageFormat").ResolveMergeFields(mergeFields); // Now add it to the check-in state message list for others to see. checkInState.Messages.Add(message); continue; } else { // Keep track of anyone who was checked in so far. if (currentOccurence == null) { currentOccurence = new OccurenceRecord() { Date = startDateTime.Date, LocationId = location.Location.Id, ScheduleId = schedule.Schedule.Id }; currentOccurences.Add(currentOccurence); } currentOccurence.Count += 1; } } } // Only create one attendance record per day for each person/schedule/group/location var attendance = attendanceService.Get(startDateTime, location.Location.Id, schedule.Schedule.Id, group.Group.Id, person.Person.Id); if (attendance == null) { var primaryAlias = personAliasService.GetPrimaryAlias(person.Person.Id); if (primaryAlias != null) { attendance = attendanceService.AddOrUpdate(primaryAlias.Id, startDateTime.Date, group.Group.Id, location.Location.Id, schedule.Schedule.Id, location.CampusId, checkInState.Kiosk.Device.Id, checkInState.CheckIn.SearchType.Id, checkInState.CheckIn.SearchValue, family.Group.Id, attendanceCode.Id); attendance.PersonAlias = primaryAlias; } } attendance.DeviceId = checkInState.Kiosk.Device.Id; attendance.SearchTypeValueId = checkInState.CheckIn.SearchType.Id; attendance.SearchValue = checkInState.CheckIn.SearchValue; attendance.CheckedInByPersonAliasId = checkInState.CheckIn.CheckedInByPersonAliasId; attendance.SearchResultGroupId = family.Group.Id; attendance.AttendanceCodeId = attendanceCode.Id; attendance.StartDateTime = startDateTime; attendance.EndDateTime = null; attendance.DidAttend = true; attendance.Note = group.Notes; KioskLocationAttendance.AddAttendance(attendance); isCheckedIntoLocation = true; // Keep track of attendance (Ids) for use by other actions later in the workflow pipeline attendanceRecords.Add(attendance); } // If the person was NOT checked into the location for any schedule then remove the location if (!isCheckedIntoLocation) { group.Locations.Remove(location); } } } } } } rockContext.SaveChanges(); // Now that the records are persisted, take the Ids and save them to the temp CheckInFamliy object family.AttendanceIds = attendanceRecords.Select(a => a.Id).ToList(); attendanceRecords = null; return(true); } return(false); }