public static RestroomSearchResultModel getFromDatabaseModel(Restroom restroom) { var restroomResult = new RestroomSearchResultModel(); restroomResult.coordX = restroom.coordX.Value; restroomResult.coordY = restroom.coordY.Value; restroomResult.id = restroom.id; restroomResult.address = restroom.address; restroomResult.gender = restroom.gender; restroomResult.description = restroom.description.Length > 100 ? restroom.description.Substring(0, 100) + "..." : restroom.description; return restroomResult; }
public RestroomModel(Restroom restroom) { this.id = restroom.id; this.Address = restroom.address; this.City = restroom.city; this.Description = restroom.description; this.Gender = restroom.gender; this.State = restroom.state; this.ZipCode = restroom.zipCode.HasValue ? "" + restroom.zipCode.Value : ""; this.userId = restroom.userId; this.coordX = restroom.coordX ?? 0; this.coordY = restroom.coordY ?? 0; }
public void AddRestroom(RestroomModel bathroom) { using (var db = new shamethethronesContext()) { Restroom newBathroom = new Restroom(); newBathroom.userId = bathroom.userId; newBathroom.address = bathroom.Address; newBathroom.city = bathroom.City; // commented out until db is changed newBathroom.state = bathroom.State; newBathroom.zipCode = Int32.Parse(bathroom.ZipCode); newBathroom.gender = bathroom.Gender; newBathroom.description = bathroom.Description; newBathroom.coordX = bathroom.coordX; newBathroom.coordY = bathroom.coordY; db.Restrooms.Add(newBathroom); db.SaveChanges(); //until testing is done bathroom.id = newBathroom.id; // sets the id so we can get it later } }
public static RestroomSearchResultModel getFromDatabaseModel(Restroom restroom, Boolean rating) { var restroomResult = new RestroomSearchResultModel(); restroomResult.coordX = restroom.coordX.Value; restroomResult.coordY = restroom.coordY.Value; restroomResult.id = restroom.id; restroomResult.address = restroom.address; restroomResult.gender = restroom.gender; var description = restroom.description ?? ""; restroomResult.description = description.Length > 100 ? description.Substring(0, 100) + "..." : description; if (rating) { RatingAverageModel ratingmodel = RestroomModel.getRatingObject(restroom.id); restroomResult.rating = ratingmodel.getAverage(); restroomResult.rated = ratingmodel.rated(); } return restroomResult; }