public virtual async Task <CreateResponse <ApiUserServerResponseModel> > Create( ApiUserServerRequestModel model) { CreateResponse <ApiUserServerResponseModel> response = ValidationResponseFactory <ApiUserServerResponseModel> .CreateResponse(await this.UserModelValidator.ValidateCreateAsync(model)); if (response.Success) { User record = this.DalUserMapper.MapModelToEntity(default(int), model); record = await this.UserRepository.Create(record); response.SetRecord(this.DalUserMapper.MapEntityToModel(record)); await this.mediator.Publish(new UserCreatedNotification(response.Record)); } return(response); }
public JsonPatchDocument <ApiUserServerRequestModel> CreatePatch(ApiUserServerRequestModel model) { var patch = new JsonPatchDocument <ApiUserServerRequestModel>(); patch.Replace(x => x.BioImgUrl, model.BioImgUrl); patch.Replace(x => x.Birthday, model.Birthday); patch.Replace(x => x.ContentDescription, model.ContentDescription); patch.Replace(x => x.Email, model.Email); patch.Replace(x => x.FullName, model.FullName); patch.Replace(x => x.HeaderImgUrl, model.HeaderImgUrl); patch.Replace(x => x.Interest, model.Interest); patch.Replace(x => x.LocationLocationId, model.LocationLocationId); patch.Replace(x => x.Password, model.Password); patch.Replace(x => x.PhoneNumber, model.PhoneNumber); patch.Replace(x => x.Privacy, model.Privacy); patch.Replace(x => x.Username, model.Username); patch.Replace(x => x.Website, model.Website); return(patch); }
public virtual ApiUserServerRequestModel MapServerResponseToRequest( ApiUserServerResponseModel response) { var request = new ApiUserServerRequestModel(); request.SetProperties( response.BioImgUrl, response.Birthday, response.ContentDescription, response.Email, response.FullName, response.HeaderImgUrl, response.Interest, response.LocationLocationId, response.Password, response.PhoneNumber, response.Privacy, response.Username, response.Website); return(request); }
public void MapModelToEntity() { var mapper = new DALUserMapper(); ApiUserServerRequestModel model = new ApiUserServerRequestModel(); model.SetProperties("A", DateTime.Parse("1/1/1987 12:00:00 AM"), "A", "A", "A", "A", "A", 1, "A", "A", "A", "A", "A"); User response = mapper.MapModelToEntity(1, model); response.BioImgUrl.Should().Be("A"); response.Birthday.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.ContentDescription.Should().Be("A"); response.Email.Should().Be("A"); response.FullName.Should().Be("A"); response.HeaderImgUrl.Should().Be("A"); response.Interest.Should().Be("A"); response.LocationLocationId.Should().Be(1); response.Password.Should().Be("A"); response.PhoneNumber.Should().Be("A"); response.Privacy.Should().Be("A"); response.Username.Should().Be("A"); response.Website.Should().Be("A"); }
public virtual async Task <UpdateResponse <ApiUserServerResponseModel> > Update( int userId, ApiUserServerRequestModel model) { var validationResult = await this.UserModelValidator.ValidateUpdateAsync(userId, model); if (validationResult.IsValid) { User record = this.DalUserMapper.MapModelToEntity(userId, model); await this.UserRepository.Update(record); record = await this.UserRepository.Get(userId); ApiUserServerResponseModel apiModel = this.DalUserMapper.MapEntityToModel(record); await this.mediator.Publish(new UserUpdatedNotification(apiModel)); return(ValidationResponseFactory <ApiUserServerResponseModel> .UpdateResponse(apiModel)); } else { return(ValidationResponseFactory <ApiUserServerResponseModel> .UpdateResponse(validationResult)); } }
public virtual User MapModelToEntity( int userId, ApiUserServerRequestModel model ) { User item = new User(); item.SetProperties( userId, model.BioImgUrl, model.Birthday, model.ContentDescription, model.Email, model.FullName, model.HeaderImgUrl, model.Interest, model.LocationLocationId, model.Password, model.PhoneNumber, model.Privacy, model.Username, model.Website); return(item); }