public Result UpdateAd(StorageAdEditInfo adInfo) { var utcNow = DateTime.UtcNow; var result = _pgClinet.NewCommand() .OnFunc("dating.ad__update") .WithParam("p_ad_id", NpgsqlDbType.Bigint, adInfo.AdId) .WithParam("p_user_id", NpgsqlDbType.Bigint, adInfo.UserId) .WithParam("p_place_id", NpgsqlDbType.Integer, adInfo.PlaceId) .WithParam("p_is_active", NpgsqlDbType.Boolean, adInfo.IsActive) .WithParam("p_date_create", NpgsqlDbType.Timestamp, utcNow) .WithParam("p_date_last_modified", NpgsqlDbType.Timestamp, utcNow) .WithParam("p_name", NpgsqlDbType.Varchar, adInfo.Name) .WithParam("p_date_born", NpgsqlDbType.Timestamp, adInfo.DateBorn) .WithParam("p_gender_id", NpgsqlDbType.Integer, adInfo.GenderId) .WithParam("p_height_cm", NpgsqlDbType.Integer, adInfo.HeightCm) .WithParam("p_weight_gr", NpgsqlDbType.Integer, adInfo.WeightGr) .WithParam("p_eye_color_id", NpgsqlDbType.Integer, adInfo.EyeColorId) .WithParam("p_hair_color_id", NpgsqlDbType.Integer, adInfo.HairColorId) .WithParam("p_hair_length_id", NpgsqlDbType.Integer, adInfo.HairLengthId) .WithParam("p_relationship_status_id", NpgsqlDbType.Integer, adInfo.RelationshipStatusId) .WithParam("p_has_kids", NpgsqlDbType.Integer, adInfo.HasKids) .WithParam("p_education_level_id", NpgsqlDbType.Integer, adInfo.EducationLevelId) .WithParam("p_smoking_id", NpgsqlDbType.Integer, adInfo.SmokingId) .WithParam("p_alcohol_id", NpgsqlDbType.Integer, adInfo.AlcoholId) .WithParam("p_religion_id", NpgsqlDbType.Integer, adInfo.ReligionId) .WithParam("p_zodiac_sign_id", NpgsqlDbType.Integer, adInfo.ZodiacSignId) .WithParam("p_body_type_id", NpgsqlDbType.Integer, adInfo.BodyTypeId) .WithParam("p_ethnic_group_id", NpgsqlDbType.Integer, adInfo.EthnicGroupId) .QueryVoidResult(); return(result); }
private Result <StorageAdEditInfo> GetValidatedStorageAdEditInfo(AdEditInfo ad) { if (ad == null) { Result <StorageAdEditInfo> .NewFailure($"{nameof(ad)} is NULL."); } var result = new StorageAdEditInfo(); result.AdId = ad.AdId; // UserId; //var resultUserAds = GetUserAds(ad.UserId); //if (!resultUserAds.Success) // return Result<StorageAdEditInfo>.NewFailure($"Failed to receive user ads by user id: '{ad.UserId}'."); //if (resultUserAds.Value.Any()) // return Result<StorageAdEditInfo>.NewFailure("User already has an ad."); result.UserId = ad.UserId; //PlaceId; var maybePlace = _placesService.GetPlace(ad.PlaceId); if (!maybePlace.Success) { return(Result <StorageAdEditInfo> .NewFailure($"Can't find place by id: {ad.PlaceId}.")); } if (!maybePlace.Value.IsEnabled) { return(Result <StorageAdEditInfo> .NewFailure($"Place '{maybePlace.Value.PlaceCode}' is not enabled.")); } if (maybePlace.Value.PlaceType != PlaceType.City) { return(Result <StorageAdEditInfo> .NewFailure($"Place '{maybePlace.Value.PlaceCode}' is not of type '{PlaceType.City}'.")); } result.PlaceId = ad.PlaceId; //Name; result.Name = ad.Name; //DateBorn; if (ad.DateBorn < DateTime.Now.AddYears(-80) || ad.DateBorn > DateTime.Now.AddYears(-18)) { return(Result <StorageAdEditInfo> .NewFailure($"{nameof(ad.DateBorn)} is invalid. (Too old or too young.")); } result.DateBorn = ad.DateBorn; //GenderId; if (!ObjectIsEnabledOfType(objectTypeCode: ObjectTypeCodes.Gender, objectId: ad.GenderId)) { return(Result <StorageAdEditInfo> .NewFailure($"{nameof(ad.GenderId)} did not pass validation.")); } result.GenderId = ad.GenderId; //HeightCm; if (ad.HeightCm.HasValue && (ad.HeightCm.Value < 110 || ad.HeightCm > 250)) { return(Result <StorageAdEditInfo> .NewFailure($"Height is invalid.")); } result.HeightCm = ad.HeightCm; //WeightGr; if (ad.WeightGr.HasValue && (ad.WeightGr < 30 * 1000 || ad.WeightGr > 200 * 1000)) { return(Result <StorageAdEditInfo> .NewFailure($"Weight is invalid.")); } result.WeightGr = ad.WeightGr; //EyeColorId; if (ad.EyeColorId.HasValue && !ObjectIsEnabledOfType(objectTypeCode: ObjectTypeCodes.EyeColor, objectId: ad.EyeColorId.Value)) { return(Result <StorageAdEditInfo> .NewFailure($"{nameof(ad.EyeColorId)} did not pass validation.")); } result.EyeColorId = ad.EyeColorId; //HairColorId; if (ad.HairColorId.HasValue && !ObjectIsEnabledOfType(objectTypeCode: ObjectTypeCodes.HairColor, objectId: ad.HairColorId.Value)) { return(Result <StorageAdEditInfo> .NewFailure($"{nameof(ad.HairColorId)} did not pass validation.")); } result.HairColorId = ad.HairColorId; //HairLengthId; if (ad.HairLengthId.HasValue && !ObjectIsEnabledOfType(objectTypeCode: ObjectTypeCodes.HairLength, objectId: ad.HairLengthId.Value)) { return(Result <StorageAdEditInfo> .NewFailure($"{nameof(ad.HairLengthId)} did not pass validation.")); } result.HairLengthId = ad.HairLengthId; return(Result <StorageAdEditInfo> .NewSuccess(result)); }