public User CreateUser(string userId, string email) { var user = new User(); user.Id = userId; user.Email = email; user.CreationDate = DateTime.UtcNow; _dbContext.Users.Add(user); _dbContext.SaveChanges(); return(user); }
public int Create(int placeTypeId, string placeName, string latitude, string longitude) { var place = new Place(); place.CreationDate = DateTime.UtcNow; var placeType = _dbContext.PlaceTypes.Find(placeTypeId); place.PlaceType = placeType; place.Name = placeName; var lat = float.Parse(latitude, CultureInfo.InvariantCulture); var lng = float.Parse(longitude, CultureInfo.InvariantCulture); place.Location = new Point(lng, lat) { SRID = 0 }; _dbContext.Places.Add(place); _dbContext.SaveChanges(); return(place.Id); }
public async Task <int> Create(MeetingModel meeting) { var creator = _dbContext.Users.Find(meeting.UserId); string title = ""; // create default title if none specified if (string.IsNullOrEmpty(meeting.Title)) { title = "Balade avec " + creator.Name; } else { title = meeting.Title; } var meetingDTO = new Meeting(); meetingDTO.PlaceId = meeting.PlaceId; meetingDTO.UserId = meeting.UserId; meetingDTO.Title = title; meetingDTO.StartDate = meeting.StartDate; meetingDTO.EndDate = meeting.StartDate + meeting.Duration; meetingDTO.CreationDate = DateTime.UtcNow; _dbContext.Meetings.Add(meetingDTO); _dbContext.SaveChanges(); //commit to get meeting id var attendee = new UserMeeting(); attendee.MeetingId = meetingDTO.Id; attendee.UserId = meeting.UserId; attendee.Status = (int)UserMeetingStatus.Going; attendee.CreationDate = DateTime.UtcNow; attendee.ModificationDate = DateTime.UtcNow; _dbContext.UserMeetings.Add(attendee); string placeName = _dbContext.Places.Find(meeting.PlaceId).Name; var allOtherUsers = _dbContext.Users.Where(user => user.Id != creator.Id).ToList(); foreach (var friend in allOtherUsers) { attendee = new UserMeeting(); attendee.MeetingId = meetingDTO.Id; attendee.UserId = friend.Id; attendee.Status = (int)UserMeetingStatus.Pending; attendee.CreationDate = DateTime.UtcNow; attendee.ModificationDate = DateTime.UtcNow; _dbContext.UserMeetings.Add(attendee); } using (var sender = new Sender(_notificationSettings.FirebaseServerKey)) { var registrationIds = allOtherUsers .Where(user => !string.IsNullOrEmpty(user.PushToken)) .Select(user => user.PushToken) .ToList(); var message = new Message { RegistrationIds = registrationIds, Notification = new Notification { Title = creator.Name + " est parti en balade", Body = "Cliquez ici pour rejoindre la balade", ClickAction = _endpointSettings.Spa + "/#/meeting/" + meetingDTO.Id, Icon = _notificationSettings.IconUrl, Badge = _notificationSettings.BadgeUrl } }; var result = await sender.SendAsync(message); } _dbContext.SaveChanges(); return(meetingDTO.Id); }