コード例 #1
0
        public async Task Delete(string id)
        {
            CategoryViewModel categoryModel = this.Get(id);

            ShopApp.Models.Category categoryEntity = this.dbContext.Categories.FirstOrDefault(c => c.Id == categoryModel.Id);

            this.dbContext.Categories.Remove(categoryEntity);
            await this.dbContext.SaveChangesAsync();
        }
コード例 #2
0
        public string GetDefaultCategory()
        {
            ShopApp.Models.Category defaultCategory = this._dbContext.Categories.FirstOrDefault();

            if (defaultCategory == null)
            {
                return(string.Empty);
            }

            return(defaultCategory.Name);
        }
コード例 #3
0
        public async Task Edit(CategoryInputModel model)
        {
            ShopApp.Models.Category categoryEntity = this.dbContext.Categories.FirstOrDefault(c => c.Id == model.Id);

            if (categoryEntity != null)
            {
                categoryEntity.Name     = model.Name;
                categoryEntity.CoverUrl = model.CoverUrl;

                await this.dbContext.SaveChangesAsync();
            }
        }
コード例 #4
0
        public async Task <CategoryInputModel> Create(CategoryInputModel model)
        {
            if (this.dbContext.Categories.Any(c => c.Name == model.Name))
            {
                throw new InvalidOperationException("Category already exists!");
            }

            ShopApp.Models.ShopUser user = this.userService.GetUserById(model.CreatorId);

            ShopApp.Models.Category categoryEntity = new ShopApp.Models.Category
            {
                Id        = Guid.NewGuid().ToString(),
                Name      = model.Name,
                CoverUrl  = model.CoverUrl,
                CreatedOn = DateTime.UtcNow,
                CreatorId = user.Id
            };

            this.dbContext.Categories.Add(categoryEntity);
            await this.dbContext.SaveChangesAsync();

            return(model);
        }