public async Task <IActionResult> AddPublication(PublicationAddDto publicationAddDto)
        {
            var user = await _userManager.GetUserAsync(HttpContext.User);

            var pub = _mapper.Map <Publication>(publicationAddDto);

            pub.Owner = user;
            _repo.Add(pub);
            if (publicationAddDto.Files != null)
            {
                //Save the publication to get the new id
                if (!await _repo.Save())
                {
                    throw new Exception("ERROR, Problem occured while adding the publication");
                }

                foreach (string filepath in publicationAddDto.Files)
                {
                    _repo.Add(new Attachment
                    {
                        PublicationId = pub.PublicationId,
                        path          = filepath
                    });
                }
            }

            if (await _repo.Save())
            {
                return(Ok("Publication added successfully !"));
            }
            throw new Exception("ERROR, Problem occured while adding the publication");
        }
예제 #2
0
        public async Task <IActionResult> AjouterClasse(ClassForCrudDto classForCrudDto)
        {
            var classe = _mapper.Map <Class>(classForCrudDto);

            classe.Owner = _userManager.GetUserAsync(HttpContext.User).Result;
            _repo.Add(classe);
            var classmember = new ClassAppUser
            {
                Class    = classe,
                Member   = classe.Owner,
                verified = true
            };

            _repo.Add(classmember);


            if (await _repo.Save())
            {
                return(Ok("Class added successfully !"));
            }
            throw new Exception("ERROR, Problem occured while adding you to the class members");
        }
예제 #3
0
        public async Task <IActionResult> AddComment(CommentForAddDto commentForAddDto)
        {
            var user = await _userManager.GetUserAsync(HttpContext.User);

            var comment = _mapper.Map <Comment>(commentForAddDto);

            comment.Owner = user;
            _repo.Add(comment);

            if (await _repo.Save())
            {
                return(Ok("Comment added successfully !"));
            }
            throw new Exception("ERROR, Problem occured while adding the Comment");
        }