public async Task <IActionResult> Create(TagCreateModel model)
 {
     if (ModelState.IsValid)
     {
         Tag tag = new Tag()
         {
             FacultyId = model.FacultyId, Name = model.Name
         };
         if (IsUniqueTag(tag.Name, tag.FacultyId))
         {
             if (await _dbContext.Tags.AddAsync(tag) != null)
             {
                 if (await _dbContext.SaveChangesAsync() > 0)
                 {
                     return(RedirectToAction("Index", "Tags"));
                 }
             }
         }
         else
         {
             ModelState.AddModelError("", "Tag already exists in daatabase");
         }
     }
     else
     {
         ModelState.AddModelError("", "Enter correct data");
     }
     return(RedirectToAction("Index", "Tags"));
 }
Esempio n. 2
0
        public async Task <IActionResult> CreateTag([FromBody] TagCreateModel model)
        {
            var result = await _tagService.CreateTag(_mapper.Map <TagDTO>(model));

            return(CreatedAtAction(nameof(GetTagById), new
            {
                id = result.Id
            }, result));
        }
Esempio n. 3
0
 public IActionResult Register(TagCreateModel model)
 {
     return(Ok(_tagService.UpsertMany(_mapper.Map <Tag>(model))));
 }
Esempio n. 4
0
        public async Task <IActionResult> UpdateTag(int id, [FromBody] TagCreateModel model)
        {
            await _tagService.UpdateTag(id, _mapper.Map <TagDTO>(model));

            return(NoContent());
        }