Esempio n. 1
0
        public async Task <IActionResult> PutCategoriesDetails([FromRoute] int id, [FromBody] CategoriesDetails categoriesDetails)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(NoContent());
        }
Esempio n. 2
0
        public async Task <IActionResult> Create([Bind("Id,Name")] Category category)
        {
            if (ModelState.IsValid)
            {
                _context.Add(category);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(category));
        }
        public async Task <ActionResult> Create([Bind(Include = "CatID,Categoria")] Category category)
        {
            if (ModelState.IsValid)
            {
                db.Categories.Add(category);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(category));
        }
Esempio n. 4
0
        public async Task <CategoryDto> InsertAsync(CategoryDto dto, CancellationToken cancellationToken)
        {
            try
            {
                var cat = new Core.Models.Category
                {
                    Title      = dto.Title,
                    Color      = dto.Color,
                    is_deleted = false,
                    created_at = DateTime.UtcNow,
                };

                await _dbContext.Categories.AddAsync(cat, cancellationToken);

                await _dbContext.SaveChangesAsync(cancellationToken);

                return(cat.MapToDto());
            }
            catch (Exception e)
            {
                _logger.LogError(e, "InsertAsync");
                throw;
            }
        }
 public Task Save()
 {
     return(_appDbContext.SaveChangesAsync());
 }