Example #1
0
        public async Task <IActionResult> PutArtefactCategory(string id, ArtefactCategory artefactCategory)
        {
            if (id != artefactCategory.ArtefactId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
        public ArtefactCategoryDto GetById(int artefactCategoryId)
        {
            ArtefactCategory category = Db.ArtefactCategories.Find(artefactCategoryId);

            if (category == null)
            {
                NotFoundException();
            }

            return(Mapper.Map <ArtefactCategoryDto>(category));
        }
        public bool Delete(int artefactCategoryId)
        {
            ArtefactCategory category = Db.ArtefactCategories.FirstOrDefault(m => m.Id == artefactCategoryId);

            if (category == null)
            {
                NotFoundException();
            }

            category.IsDeleted    = true;
            category.ModifiedDate = DateTime.UtcNow;

            Db.SaveChanges();

            return(true);
        }
Example #4
0
        public async Task <ActionResult <ArtefactCategory> > PostArtefactCategory(ArtefactCategory artefactCategory)
        {
            _context.ArtefactCategory.Add(artefactCategory);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (ArtefactCategoryExists(artefactCategory.ArtefactId))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetArtefactCategory", new { id = artefactCategory.ArtefactId }, artefactCategory));
        }
        public ArtefactCategoryDto Create(ArtefactCategoryDto dto)
        {
            if (string.IsNullOrEmpty(dto.Name))
            {
                throw new ArgumentNullException("Name");
            }

            ArtefactCategory category = new ArtefactCategory
            {
                Name         = dto.Name,
                Description  = dto.Description,
                Image        = dto.Image,
                CreatedDate  = DateTime.UtcNow,
                ModifiedDate = DateTime.UtcNow,
                IsDeleted    = false
            };

            Db.ArtefactCategories.Add(category);

            Db.SaveChanges();

            return(Mapper.Map <ArtefactCategoryDto>(category));
        }
        public ArtefactCategoryDto Update(ArtefactCategoryDto dto)
        {
            if (string.IsNullOrEmpty(dto.Name))
            {
                throw new ArgumentNullException("Name");
            }

            ArtefactCategory category = Db.ArtefactCategories.FirstOrDefault(m => m.Id == dto.Id);

            if (category == null)
            {
                NotFoundException();
            }

            category.Name         = dto.Name;
            category.Description  = dto.Description;
            category.Image        = dto.Image;
            category.ModifiedDate = DateTime.UtcNow;
            category.IsDeleted    = dto.IsDeleted;

            Db.SaveChanges();

            return(Mapper.Map <ArtefactCategoryDto>(category));
        }