Esempio n. 1
0
        public async Task <CategoryDto> AddOrUpdateAsync(CategoryDto model)
        {
            if (model.Id == 0)
            {
                // new category
                return(await AddCategoryAsync(model));
            }
            else
            {
                var entity = await dbContext.Categories.FirstOrDefaultAsync(x => x.Id == model.Id);

                if (entity == null)
                {
                    return(await AddCategoryAsync(model));
                }
                entity.CategoryName = model.Name;
                entity.Slug         = model.Slug.ToLower();
                dbContext.Categories.Update(entity);
                await dbContext.SaveChangesAsync();

                return(ToDto(entity));
            }
        }
Esempio n. 2
0
        public async Task <SkillModel> CreateUpdateSkillAsync(SkillModel model)
        {
            if (model.Id == 0)
            {
                return(await CreateSkillAsync(model));
            }
            var entity = await dbContext.Skills.FirstOrDefaultAsync(x => x.Id == model.Id);

            if (entity == null)
            {
                return(null);
            }
            entity.Name       = model.Name;
            entity.Percentage = model.Percentage;
            dbContext.Update(entity);
            await dbContext.SaveChangesAsync();

            return(new SkillModel
            {
                Id = entity.Id,
                Name = entity.Name,
                Percentage = entity.Percentage
            });
        }