Esempio n. 1
0
        public async Task <Recommendation> Add(CreateRecommedationInputModel input)
        {
            var alreadyExists = await db.Recommendations.AsQueryable()
                                .Where(r => r.InterestId == input.InterestId)
                                .Where(r => r.PersonaId == input.PersonaId)
                                .SingleOrDefaultAsync();

            if (alreadyExists != null)
            {
                throw new EntityAlreadyExistsException <Recommendation>(alreadyExists);
            }

            var recommendation = new Recommendation()
            {
                InterestId = input.InterestId,
                PersonaId  = input.PersonaId,
                Context    = input.Context,
                AddedBy    = PrincipalUsername,
                CreatedAt  = DateTime.Now,
            };

            var fromDb = db.Recommendations.Add(recommendation);

            await db.SaveChangesAsync();

            return(fromDb.Entity);
        }
Esempio n. 2
0
        public async Task <ActionResult <Recommendation> > PostRecommendation(CreateRecommedationInputModel inputData)
        {
            Recommendation recommendation;

            try
            {
                recommendation = await _service.Add(inputData);
            }
            catch (EntityAlreadyExistsException <Recommendation> ex)
            {
                return(Ok(ex.Entity));
            }

            return(CreatedAtAction("GetRecommendation", new { id = recommendation.Id }, recommendation));
        }
Esempio n. 3
0
 public Task Update(long id, CreateRecommedationInputModel persona)
 {
     throw new NotImplementedException();
 }