public async Task <IQRScanResponse> JoinAdminEventByShortCodeAsync(int eventid, string shortCode) { QRScanView _response = new QRScanView(); try { //var user = await _appDbContext.Users.FirstOrDefaultAsync(x => x.Id == userId); //char[] spearator = { '-' }; //var Scans = qrCode.Split(spearator); var Scans = (shortCode != "" && shortCode != null) ? Convert.ToInt32(shortCode) : 0; Scans = (Scans != 0) ? Scans + 100 : Scans; var item = await _appDbContext.Profiles.FirstOrDefaultAsync(e => e.Id == Scans); if (item == null) { return(new QRScanResponse(ClientMessageConstant.InvalidShortCode, HttpStatusCode.NotFound)); } var usereventJoin = await _appDbContext.ProfileEvents.FirstOrDefaultAsync(e => e.EventId == item.Id && e.ProfileId == item.Id && e.EventStatusItemId == 69001); if (_appDbContext.ProfileEvents.Any(e => e.EventId == eventid && e.ProfileId == item.Id && e.EventStatusItemId == 69001)) { return(new QRScanResponse(ClientMessageConstant.AlreadyJoined, HttpStatusCode.AlreadyReported)); } else { var events = await _appDbContext.Events.FirstOrDefaultAsync(e => e.Id == eventid); Application application = null; int batchid = (events.BatchId.HasValue) ? events.BatchId.Value : 0; if (batchid != 0) { application = await _appDbContext.Applications.FirstOrDefaultAsync(k => k.ProfileId == item.Id && k.BatchId == batchid && k.StatusItemId == (int)ApplicationProgressStatus.Accepted); } if (events.BatchId != null && application == null) { return(new QRScanResponse(ClientMessageConstant.NotEligible, HttpStatusCode.NotFound)); } _appDbContext.ProfileEvents.Add(new ProfileEvent { ProfileId = item.Id, EventId = eventid, EventStatusItemId = 69001 }); _appDbContext.SaveChanges(); } return(new QRScanResponse(69001)); } catch (Exception e) { return(new QRScanResponse(e)); } }
public async Task <IQRScanResponse> ScanQRCodeAsync(int userId, string _data) { QRScanView _response = new QRScanView(); try { //var user = await _appDbContext.Users.FirstOrDefaultAsync(x => x.Id == userId); char[] spearator = { '-' }; var Scans = _data.Split(spearator); if (Scans[0] == "Meetup") { var code = Convert.ToInt32(Scans[1]); var item = await _appDbContext.Meetups.FirstOrDefaultAsync(e => e.Id == code); if (item == null) { return(new QRScanResponse(ClientMessageConstant.InvalidQRCode, HttpStatusCode.NotFound)); } else { } int profileId = userId; var commentUser = await _appDbContext.Users.FirstOrDefaultAsync(x => x.Id == profileId); var commentUserJob = await _appDbContext.ProfileWorkExperiences.Include(m => m.Title) .Where(k => k.ProfileId == profileId).OrderByDescending(k => k.DateFrom) .FirstOrDefaultAsync(); int?smallImageFileId = commentUser.SmallImageFileId; if (smallImageFileId.HasValue) { smallImageFileId = commentUser.SmallImageFileId; } _response.UserNameEN = commentUser.NameEn; _response.UserNameAR = commentUser.NameAr; _response.DesignationEN = commentUserJob?.Title?.TitleEn; _response.DesignationAR = commentUserJob?.Title?.TitleAr; _response.UserId = profileId; _response.ProfileImageId = smallImageFileId; _response.EventNameEN = item.Title; _response.EventNameAR = ""; _response.LocationTextAR = ""; _response.LocationTextEN = ""; _response.Location = new MapAutocompleteView() { Latitude = item.Latitude, Longitude = item.Longitude, Text = item.MapText }; _response.MeetupId = item.Id; } else if (Scans[0] == "Event") { var code = Scans[1]; var item = await _appDbContext.Events.Include(a => a.EventDays).FirstOrDefaultAsync(e => e.QRCode == code); if (item == null) { return(new QRScanResponse(ClientMessageConstant.InvalidQRCode, HttpStatusCode.NotFound)); } //else if (true) //{ //} else { } int profileId = userId; var commentUser = await _appDbContext.Users.FirstOrDefaultAsync(x => x.Id == profileId); var commentUserJob = await _appDbContext.ProfileWorkExperiences.Include(m => m.Title) .Where(k => k.ProfileId == profileId).OrderByDescending(k => k.DateFrom) .FirstOrDefaultAsync(); int?smallImageFileId = commentUser.SmallImageFileId; if (smallImageFileId.HasValue) { smallImageFileId = commentUser.SmallImageFileId; } _response.UserNameEN = commentUser.NameEn; _response.UserNameAR = commentUser.NameAr; _response.DesignationEN = commentUserJob?.Title?.TitleEn; _response.DesignationAR = commentUserJob?.Title?.TitleAr; _response.UserId = profileId; _response.ProfileImageId = smallImageFileId; _response.EventNameEN = item.TextEn; _response.EventNameAR = item.TextAr; _response.LocationTextAR = item.LocationAr; _response.LocationTextEN = item.LocationEn; _response.Location = new MapAutocompleteView() { Latitude = item.Latitude, Longitude = item.Longitude, Text = item.MapText }; _response.EventId = item.Id; } return(new QRScanResponse(_response)); } catch (Exception e) { return(new QRScanResponse(e)); } }
public QRScanResponse(QRScanView meetup) : this(true, string.Empty, meetup) { }
public async Task <IQRScanResponse> JoinEventByQRCodeAsync(int userId, int decisionId, string _data) { QRScanView _response = new QRScanView(); try { //var user = await _appDbContext.Users.FirstOrDefaultAsync(x => x.Id == userId); char[] spearator = { '-' }; var Scans = _data.Split(spearator); if (Scans[0] == "Meetup") { var code = Convert.ToInt32(Scans[1]); var item = await _appDbContext.Meetups.FirstOrDefaultAsync(e => e.Id == code); if (item == null) { return(new QRScanResponse(ClientMessageConstant.InvalidQRCode, HttpStatusCode.NotFound)); } else { if (item.Date.Date < DateTime.Now.Date) { return(new QRScanResponse(ClientMessageConstant.PastEvent, HttpStatusCode.NotFound)); } else if (item.Date.Date > DateTime.Now.Date) { return(new QRScanResponse(ClientMessageConstant.FutureEvent, HttpStatusCode.NotFound)); } } //throw new ArgumentException("Invalid Scan Data: " + _data); if (_appDbContext.ProfileMeetups.Any(m => m.MeetupId == item.Id && m.ProfileId == userId && m.MeetupStatusItemId == 69001)) { return(new QRScanResponse(ClientMessageConstant.AlreadyJoined, HttpStatusCode.AlreadyReported)); } //_appDbContext.ProfileMeetups.FirstOrDefault(m => m.MeetupId == item.Id && m.ProfileId == userId).MeetupStatusItemId = decisionId; else { _appDbContext.ProfileMeetups.Add(new ProfileMeetup { ProfileId = userId, MeetupId = item.Id, MeetupStatusItemId = decisionId }); _appDbContext.SaveChanges(); } } else if (Scans[0] == "Event") { var item = await _appDbContext.Events.FirstOrDefaultAsync(e => e.QRCode == Scans[1]); if (item == null) { return(new QRScanResponse(ClientMessageConstant.InvalidQRCode, HttpStatusCode.NotFound)); } else { var eventDate = await _appDbContext.EventDays.FirstOrDefaultAsync(e => e.EventId == item.Id); if (eventDate != null) { if (eventDate.Date < DateTime.Now.Date) { return(new QRScanResponse(ClientMessageConstant.PastEvent, HttpStatusCode.NotFound)); } else if (eventDate.Date > DateTime.Now.Date) { return(new QRScanResponse(ClientMessageConstant.FutureEvent, HttpStatusCode.NotFound)); } } } if (_appDbContext.ProfileEvents.Any(m => m.EventId == item.Id && m.ProfileId == userId && m.EventStatusItemId == 69001)) { return(new QRScanResponse(ClientMessageConstant.AlreadyJoined, HttpStatusCode.AlreadyReported)); } // _appDbContext.ProfileEvents.FirstOrDefault(m => m.EventId == item.Id && m.ProfileId == userId).EventStatusItemId = decisionId; else { Application application = null; int batchid = (item.BatchId.HasValue) ? item.BatchId.Value : 0; if (batchid != 0) { application = await _appDbContext.Applications.FirstOrDefaultAsync(k => k.ProfileId == userId && k.BatchId == batchid && k.StatusItemId == (int)ApplicationProgressStatus.Accepted); } if (item.BatchId != null && application == null) { return(new QRScanResponse(ClientMessageConstant.NotEligible, HttpStatusCode.NotFound)); } if (_appDbContext.ProfileEvents.Any(m => m.EventId == item.Id && m.ProfileId == userId)) { var profileEvent = await _appDbContext.ProfileEvents.FirstOrDefaultAsync(m => m.EventId == item.Id && m.ProfileId == userId); profileEvent.EventStatusItemId = decisionId; _appDbContext.SaveChanges(); } else { _appDbContext.ProfileEvents.Add(new ProfileEvent { ProfileId = userId, EventId = item.Id, EventStatusItemId = decisionId }); _appDbContext.SaveChanges(); } } } else { return(new QRScanResponse(ClientMessageConstant.InvalidQRCode, HttpStatusCode.NotFound)); } return(new QRScanResponse(decisionId)); } catch (Exception e) { return(new QRScanResponse(e)); } }
private QRScanResponse(bool success, string message, QRScanView meetup) : base(success, message) { UserScanView = meetup; }