示例#1
0
        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));
        }
示例#2
0
        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);
        }
示例#3
0
        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)));
            }
        }
示例#4
0
 public Task Update(long id, CreateInterestInputModel persona)
 {
     throw new NotImplementedException();
 }