public async Task <IActionResult> PutCategory([FromRoute] Guid id, [FromBody] Category category)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != category.Id)
            {
                return(BadRequest());
            }

            _context.Entry(category).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CategoryExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemple #2
0
        public async Task <IActionResult> Create([Bind("Id,Name,Description")] CategoryViewModel categoryViewModel)
        {
            if (ModelState.IsValid)
            {
                categoryViewModel.Id = Guid.NewGuid();
                Category model = _mapper.Map <CategoryViewModel, Category>(categoryViewModel);
                _context.Add(model);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(categoryViewModel));
        }
Exemple #3
0
        public async Task <bool> Create(Post post, CancellationToken cancellationToken)
        {
            try
            {
                await _context.Posts.AddAsync(post);

                await _context.SaveChangesAsync();

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Exemple #4
0
        public async Task <int?> Create(Profile profile, CancellationToken cancellationToken)
        {
            try
            {
                await _context.Profiles.AddAsync(profile);

                await _context.SaveChangesAsync();

                return(profile.Id);
            }
            catch
            {
                return(null);
            }
        }
        public async Task <bool> Insert(User user, CancellationToken cancellationToken = default)
        {
            try
            {
                await _context.Users.AddAsync(user);

                await _context.SaveChangesAsync();

                return(true);
            }catch
            {
                return(false);
            }
        }