public bool InsertInterest(InterestDto interest) { return(_context.Interests.Add(new Interest { UserId = interest.UserId, Title = interest.Title, Summary = interest.Summary, CreateDate = DateTime.Now }) != null); }
public bool InterestsPost(int trainerid, InterestDto interestDto) { Interest interest = new Interest() { Name = interestDto.Name, TrainerId = trainerid }; datacontext.Interests.Add(interest); return(datacontext.SaveChanges() != -1); }
private bool AddInterest(string userId, InterestViewModel interest) { var addRecord = new InterestDto() { UserId = userId, Title = interest.Title, Summary = interest.Summary }; return(_interestService.InsertInterest(userId, addRecord)); }
private bool UpdateInterest(string userId, InterestViewModel interest) { var updateRecord = new InterestDto() { Id = interest.Id, UserId = userId, Title = interest.Title, Summary = interest.Summary }; return(_interestService.UpdateInterest(userId, updateRecord)); }
public async Task TestInsertPerfilPersonal_Then_ModifyIt() { IServiceCollection services = BuildDependencies(); using (ServiceProvider serviceProvider = services.BuildServiceProvider()) { string username = Guid.NewGuid().ToString(); PersonalProfileDto defaultPRofile = BuildPersonalProfile(username); var departmentAppService = serviceProvider.GetRequiredService <PerfilPersonalController>(); await departmentAppService.Post(defaultPRofile); ResultDto <PersonalProfileDto> resultUserStep1 = await departmentAppService.Get(username); Assert.Empty(resultUserStep1.Errors); PersonalProfileDto userStep1 = resultUserStep1.Value; Assert.Empty(userStep1.Skills); Assert.Equal(defaultPRofile.FirstName, userStep1.FirstName); Assert.Equal(defaultPRofile.Website, userStep1.Website); Assert.Equal(defaultPRofile.LastName, userStep1.LastName); SkillDto skill = new SkillDto() { Id = null, Name = "nombre1", Punctuation = 10m }; userStep1.Skills.Add(skill); InterestDto interest = new InterestDto() { Id = null, Interest = "interes pero debe contener 15 caracteres" }; userStep1.Interests.Add(interest); var _ = await departmentAppService.Put(userStep1); //TODO: change back to get ResultDto <PersonalProfileDto> resultUserStep2 = await departmentAppService.Get(username); Assert.Empty(resultUserStep2.Errors); PersonalProfileDto userStep2 = resultUserStep1.Value; Assert.Single(userStep2.Skills); Assert.Equal(skill.Name, userStep2.Skills.First().Name); Assert.Single(userStep2.Interests); Assert.Equal(interest.Interest, userStep2.Interests.First().Interest); Assert.Equal(defaultPRofile.FirstName, userStep2.FirstName); Assert.Equal(defaultPRofile.Website, userStep2.Website); Assert.Equal(defaultPRofile.LastName, userStep2.LastName); Assert.Equal(defaultPRofile.Email, userStep2.Email); } }
public IHttpActionResult Follow(InterestDto dto) { var followerId = User.Identity.GetUserId(); if (_interestRepository.IsInterested(dto.IdeaId, followerId)) { return(BadRequest("You are already interested in this Idea")); } _interestRepository.Add(dto.IdeaId, followerId); return(Ok()); }
public bool UpdateInterest(InterestDto interest) { var record = _context.Interests.FirstOrDefault(x => x.Id == interest.Id); if (record == null) { return(false); } record.Title = interest.Title; record.Summary = interest.Summary; _context.Interests.AddOrUpdate(record); return(_context.SaveChanges() == 1); }
public IHttpActionResult CreateInterest(InterestDto interestDto) { if (!ModelState.IsValid) { return(BadRequest()); } var interest = Mapper.Map <InterestDto, Interests>(interestDto); _context.Interests.Add(interest); _context.SaveChanges(); interestDto.Id = interest.Id; return(Created(new Uri(Request.RequestUri + "/" + interest.Id), interestDto)); }
public async Task TestPostUserAsync() { var testInterest = new InterestDto { Id = Guid.NewGuid().ToString(), InterestName = "Vine Swinging", InterestType = "Outdoors" }; var listOfTestInterests = new List <InterestDto> { testInterest }; var testUser = new UserDto { FirstName = "Jane", LastName = "Tarzan", Id = Guid.NewGuid().ToString(), MyAddress = new AddressDto { City = "Forbidden", Country = "United States", Id = Guid.NewGuid().ToString(), State = "Florida", Street1 = "One Big Tree House Way", Street2 = string.Empty, ZipCode = "98798" }, MyInterests = listOfTestInterests }; var requestMessage = JsonConvert.SerializeObject(testUser); var content = new StringContent(requestMessage, Encoding.UTF8, "application/json"); var response = await _client.PostAsync("/api/Users", content); var returnedMessage = await response.Content.ReadAsStringAsync(); Console.WriteLine(returnedMessage); // Handle response status await response.EnsureSuccessStatusCodeAsync(); }
public IHttpActionResult UpdateInterest(int id, InterestDto interestDto) { if (!ModelState.IsValid) { return(BadRequest()); } var interestInDb = _context.Interests.SingleOrDefault(i => i.Id == id); if (interestInDb == null) { return(NotFound()); } Mapper.Map(interestDto, interestInDb); _context.SaveChanges(); return(Ok()); }
public bool UpdateInterest(string userId, InterestDto interest) { try { //Validate user if (_userRepository.IsAuthenticated(userId)) { var record = _interestRepository.GetInterestById(interest.Id.ToString());; if (record != null) { interest.CreateDate = record.CreateDate; //Validate Model ICollection <ValidationResult> results; if (IsValidModel(interest, out results)) { if (ModelCompareChecker.Compare(interest, record)) { return(true); } record.Title = interest.Title; record.Summary = interest.Summary; return(_interestRepository.UpdateInterest(record)); } _loggingService.Info("Model Validation Failed: " + interest); } } _loggingService.Info("UserId Authenticated Failed: " + userId); } catch (Exception ex) { //Error _loggingService.Error("An error has occurred", ex); } //Fail return(false); }
public bool InsertInterest(string userId, InterestDto interest) { try { //Validate user if (_userRepository.IsAuthenticated(userId)) { //Validate Model ICollection <ValidationResult> results; if (IsValidModel(interest, out results)) { //Call Repository if (_interestRepository.InsertInterest(interest)) { //Save if (_interestRepository.Save()) { //Success return(true); } _loggingService.Info("Failed To Save"); } _loggingService.Info("UserRepository Failed Insert"); } _loggingService.Info("Model Validation Failed: " + interest); } _loggingService.Info("UserId Authenticated Failed: " + userId); } catch (Exception ex) { //Error _loggingService.Error("An error has occurred", ex); } //Fail return(false); }
public InterestsResponse GetInterestsRespose(Client client, Agreement agreement, InterestDto interestDto) { var agreementDto = _mapper.Map <AgreementDto>(agreement); var clientDto = _mapper.Map <ClientDto>(client); return(new InterestsResponse { Client = clientDto, Agreement = agreementDto, Interests = interestDto, }); }