Пример #1
0
        public IHttpActionResult AddTagToVideo([FromUri] int id, [FromBody] AddTagBindingModel model)
        {
            var currentLoggedUserId = User.Identity.GetUserId();

            var currentVideo = db.Videos.Find(id);

            var currentTag = db.Tags.Find(model.TagId);

            if (currentVideo == null)
            {
                return(NotFound());
            }

            if (currentTag == null)
            {
                return(NotFound());
            }

            if (currentLoggedUserId == null)
            {
                return(Unauthorized());
            }

            currentVideo.Tags.Add(currentTag);
            db.SaveChanges();
            return(this.Ok());
        }
Пример #2
0
        public async Task <IHttpActionResult> AddTag(AddTagBindingModel model)
        {
            var db         = IlevusDBContext.Create();
            var filters    = Builders <CoachingProcess> .Filter;
            var updates    = Builders <CoachingProcess> .Update;
            var collection = db.GetCoachingProcessCollection();

            try
            {
                var process = (await collection.FindAsync(filters.Eq("Id", model.ProcessId))).FirstOrDefault();
                if (process != null)
                {
                    var session = process.Sessions[model.Session];
                    if (session == null)
                    {
                        return(BadRequest("Sessão inválida."));
                    }
                    if (session.Tags == null)
                    {
                        session.Tags = new List <string>();
                    }
                    session.Tags.Add(model.Tag);
                    await collection.UpdateOneAsync(filters.Eq("Id", model.ProcessId),
                                                    updates.Combine(
                                                        updates.Set("Sessions", process.Sessions),
                                                        updates.Set("LastModified", DateTime.Now)
                                                        )
                                                    );

                    return(Ok(true));
                }
                return(NotFound());
            }
            catch (Exception e)
            {
                return(InternalServerError(e));
            }
        }