/// <summary> /// <see cref="IPersonService.Add(PersonModel)"/> /// </summary> /// <param name="personModel"></param> public async Task <PersonModel> Add(PersonModel personModel) { if (personModel == null) { throw new ArgumentNullException("No PersonModel passed to Add function."); } Person person = GetEntity(personModel); person.Id = Guid.NewGuid(); ICollection <PersonInterest> interests = new Collection <PersonInterest>(); if (personModel.PersonInterestIds.Count > 0) { foreach (var interestId in personModel.PersonInterestIds) { PersonInterest personInterest = new PersonInterest() { Id = Guid.NewGuid(), PersonId = person.Id, InterestId = interestId }; interests.Add(personInterest); } } await _context.AddRangeAsync(interests); await _context.AddAsync(person); await _context.SaveChangesAsync(); return(GetModel(person)); }
public async Task <IActionResult> PostPersonInterest([FromBody] PersonInterest personInterest) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.PersonInterests.Add(personInterest); try { await _context.SaveChangesAsync(); } catch (DbUpdateException) { if (PersonInterestExists(personInterest.PersonId)) { return(new StatusCodeResult(StatusCodes.Status409Conflict)); } else { throw; } } return(CreatedAtAction("GetPersonInterest", new { id = personInterest.PersonId }, personInterest)); }
public async Task <ActionResult <PersonInterest> > PostPersonInterest(PersonInterest personInterest) { _context.PersonInterest.Add(personInterest); await _context.SaveChangesAsync(); return(CreatedAtAction("GetPersonInterest", new { id = personInterest.Id }, personInterest)); }
public async Task <IActionResult> PutPersonInterest([FromRoute] int id, [FromBody] PersonInterest personInterest) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != personInterest.PersonId) { return(BadRequest()); } _context.Entry(personInterest).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PersonInterestExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
private static void ListAllPersonsWithSameInterests(PersonInterest interest) { Console.ForegroundColor = Color.DarkMagenta; Console.WriteLine("Show all persons with the inteserst: " + interest); Console.ResetColor(); using (var context = new MatchMainData()) { foreach (var person in context.Persons .Include(q => q.InterestsPerson) .Where(p => p.InterestsPerson.Select(x => x.Interests.PersonInterest).Contains(interest))) { Console.WriteLine(person.FirstName + " " + person.LastName); } } }
public PersonControllerTests() { _persons = new InMemoryDbSet <Person>(); _interests = new InMemoryDbSet <PersonInterest>(); _images = new InMemoryDbSet <PersonImage>(); for (int i = 1; i < 31; i++) { var newPerson = new Person { Id = i, DateOfBirth = new DateTime(1990, 1, i), FirstName = $"First{i}", LastName = $"last{i}", Image = new PersonImage { PersonId = i, ImageBase64 = i.ToString() }, Interests = new List <PersonInterest>(), }; for (int j = 1; j < i / 2; j++) { var newInterst = new PersonInterest { Id = i ^ j, Interest = $"Interest{i}_{j}", PersonId = i, Person = newPerson }; newPerson.Interests.Add(newInterst); _interests.Add(newInterst); } if (i == 10 || i == 11) { var snowboardingInterest = new PersonInterest { Id = 1000 + i, Interest = "Snowboarding", PersonId = i, Person = newPerson }; newPerson.Interests.Add(snowboardingInterest); _interests.Add(snowboardingInterest); } _images.Add(newPerson.Image); _persons.Add(newPerson); } _mockContext = new Mock <PeopleSearchContext>(); _mockContext.Setup(x => x.People).Returns(_persons); _mockContext.Setup(x => x.Interests).Returns(_interests); _mockContext.Setup(x => x.PersonImages).Returns(_images); _personRepository = new PersonRepository(_mockContext.Object); }
public async Task <IActionResult> PutPersonInterest(int id, PersonInterest personInterest) { personInterest.Id = id; _context.Entry(personInterest).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PersonInterestExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public ActionResult PersonInterest_Destroy([DataSourceRequest] DataSourceRequest request, PersonInterest _objPersonInterest) { if (ModelState.IsValid) { PersonSkillsInterest _objSkillsInterest = new PersonSkillsInterest(); _objSkillsInterest.UpdatedBy = CurrentUser.NameIdentifierInt64; _objSkillsInterest.UpdatedDate = DateTime.Now; _objSkillsInterest.ID = _objPersonInterest.ID; var result = _objISkillsInterestLevelBAL.PersonSkillsInterest_DeleteBAL(_objSkillsInterest); if (result == -1) { ModelState.AddModelError(lr.ErrorServerError, lr.ResourceUpdateValidationError); } } var resultData = new[] { _objPersonInterest }; return(Json(resultData.AsQueryable().ToDataSourceResult(request, ModelState))); }
public ActionResult PersonInterest_Update([DataSourceRequest] DataSourceRequest request, PersonInterest _objPersonInterest) { if (ModelState.IsValid) { PersonSkillsInterest _objSkillsInterest = new PersonSkillsInterest(); _objSkillsInterest.UpdatedBy = CurrentUser.NameIdentifierInt64; _objSkillsInterest.UpdatedDate = DateTime.Now; _objSkillsInterest.Title = _objPersonInterest.Title; _objSkillsInterest.Description = ""; _objSkillsInterest.ID = _objPersonInterest.ID; _objSkillsInterest.Type = PersonSKillInterest.PersonSKillInterest_Field_Of_Interest; if (_objISkillsInterestLevelBAL.PersonSkillsInterest_DuplicationCheckBAL(_objSkillsInterest) > 0) { ModelState.AddModelError(lr.PersonFieldofInterest, lr.PersonFieldofInterestDuplicationCheck); } else { var result = _objISkillsInterestLevelBAL.PersonSkillsInterest_UpdateBAL(_objSkillsInterest); if (result == -1) { ModelState.AddModelError(lr.ErrorServerError, lr.ResourceUpdateValidationError); } } } var resultData = new[] { _objPersonInterest }; return(Json(resultData.AsQueryable().ToDataSourceResult(request, ModelState))); }
public ActionResult PersonInterest_Create([DataSourceRequest] DataSourceRequest request, string pid, PersonInterest _objPersonInterest) { if (ModelState.IsValid) { PersonSkillsInterest _objSkillsInterest = new PersonSkillsInterest(); _objSkillsInterest.CreatedBy = CurrentUser.NameIdentifierInt64; _objSkillsInterest.PersonID = Convert.ToInt64(pid); _objSkillsInterest.OrganizationID = CurrentUser.CompanyID; _objSkillsInterest.CreatedDate = DateTime.Now; _objSkillsInterest.Title = _objPersonInterest.Title; _objSkillsInterest.Description = ""; _objSkillsInterest.Type = PersonSKillInterest.PersonSKillInterest_Field_Of_Interest; if (_objISkillsInterestLevelBAL.PersonSkillsInterest_DuplicationCheckBAL(_objSkillsInterest) > 0) { ModelState.AddModelError(lr.PersonFieldofInterest, lr.PersonFieldofInterestDuplicationCheck); } else { _objPersonInterest.ID = _objISkillsInterestLevelBAL.PersonSkillsInterest_CreateBAL(_objSkillsInterest); } } var resultData = new[] { _objPersonInterest }; return(Json(resultData.ToDataSourceResult(request, ModelState))); }