public async Task <Interest> GetOrCreate(CreateInterestInputModel input) { var interest = await db.Interests.AsQueryable() .Where(i => i.WikiId == input.WikiId) .SingleOrDefaultAsync(); return(interest ?? await Add(input)); }
public async Task <Interest> Add(CreateInterestInputModel input) { Interest currentVersion = await db.Interests.AsQueryable() .Where(e => e.WikiId == input.WikiId) .SingleOrDefaultAsync(); if (currentVersion != null) { throw new EntityAlreadyExistsException <Interest>(currentVersion); } Interest interest = await _scrappingService.ScrapeInterestDetails(input.WikiId); interest.AddedBy = PrincipalUsername; var fromDb = db.Interests.Add(interest); await db.SaveChangesAsync(); return(fromDb.Entity); }
public async Task <ActionResult <InterestViewModel> > PostInterest(CreateInterestInputModel interest) { try { Interest fromDb = await _service.Add(interest); return(CreatedAtAction("GetInterest", new { id = fromDb.Id }, fromDb)); } catch (EntityAlreadyExistsException <Interest> ex) { return(Ok(ex.Entity)); } catch (AddedEntityIsNotAnInterestException ex) { return(BadRequest(new ErrorMessage(ex.Message))); } catch (EntityNotFoundException ex) { return(BadRequest(new ErrorMessage(ex.Message))); } }
public Task Update(long id, CreateInterestInputModel persona) { throw new NotImplementedException(); }