/// <summary> /// Create a new help request for a specific help seeker if the id is 0. /// Else if a help request already exists with the same id, the existing help request will be updated. /// </summary> /// <param name="helpRequest"> /// The new or updated help request. /// </param> /// <returns> /// The created or updated help request. /// </returns> public HelpRequestModel Save(HelpRequestModel helpRequest) { //Default location GeoCoordinate location = new GeoCoordinate(52.132633, 5.291265999999999); string address = "Nederland"; //Try to get location if (helpRequest.Address != address) { GoogleMapsApi.Response googleMapsApi = GoogleMapsApi.Get(helpRequest.Address, "nl", "nl"); if (googleMapsApi != null) { location = googleMapsApi.Location; address = googleMapsApi.Address; } } helpRequest.Location = location; helpRequest.Address = address; if (helpRequest.Id == 0) { helpRequest.Id = context.Create(helpRequest); Console.WriteLine(helpRequest.Id + helpRequest.Title); } else { context.Update(helpRequest); } return(helpRequest); }
/// <summary> /// Create a new user. /// </summary> /// <param name="register"> /// The data about the new user. /// </param> public int Register(RegisterModel register) { string hash = Crypter.Blowfish.Crypt(register.Password); bool approved = register.Role == UserRole.HelpSeeker; int userId = context.Register(new UserModel { Role = register.Role, Email = register.Email, Name = register.Name, Password = hash, Birthdate = register.Birthdate }, approved); if (userId > 0) { if (register.Role == UserRole.Volunteer) { //Default location GeoCoordinate location = new GeoCoordinate(52.132633, 5.291265999999999); string address = "Nederland"; //Try to get location GoogleMapsApi.Response googleMapsApi = GoogleMapsApi.Get(register.Address, "nl", "nl"); if (googleMapsApi != null) { location = googleMapsApi.Location; address = googleMapsApi.Address; } context.RegisterVolunteer(new VolunteerModel { Id = userId, Address = address, Location = location, DriversLicense = register.DriversLicense, Car = register.Car }); } if (register.Avatar != null) { string directory = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\EyeCTforParticipation\\Uploads\\Avatars"; if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } register.Avatar.Save(directory + "\\" + userId.ToString() + ".png", System.Drawing.Imaging.ImageFormat.Png); } return(userId); } //Throw failed to register exception throw new Exception(); }
/// <summary> /// Get a list of help requests. /// </summary> /// <param name="keywords"> /// Keywords included in search results, keywords are seperated by whitespace. /// </param> /// <param name="postalCode"> /// The postal code used as the center of the search area. Example postal code: "5654 NE". /// </param> /// <param name="distance"> /// The distance used as the radius of the search area, infinite distance is 0. /// </param> /// <param name="order"> /// Order results by relevance, distance or date. /// </param> /// <returns> /// A list of help requests. /// </returns> public List <HelpRequestModel> Search(string keywords, string postalCode, int distance, SearchOrder order) { // Format postal code postalCode = FormatPostalCode(postalCode); // Default location GeoCoordinate location = null; // Try to get location from postal code GoogleMapsApi.Response googleMapsApi = GoogleMapsApi.Get(postalCode, "nl", "nl"); if (googleMapsApi != null && postalCode != null) { location = googleMapsApi.Location; } return(Search(keywords, location, distance, order)); }