예제 #1
0
        public async Task <int> Create(ProductCreateRequest request)
        {
            var product = new Entites.Product()
            {
                Name        = request.Name,
                Price       = request.Price,
                Description = request.Description,
                AppUser     = request.User,
            };

            if (request.ThumbnailImage != null)
            {
                product.ProductImages = new List <Entites.ProductImage>()
                {
                    new Entites.ProductImage()
                    {
                        DateCreated = DateTime.Now,
                        ImagePath   = await this.SaveFile(request.ThumbnailImage),
                        IsDefault   = true,
                    }
                };
            }

            context.Add(product);
            return(await context.SaveChangesAsync());
        }
예제 #2
0
        public async Task <IActionResult> PutCategory(int id, Category category)
        {
            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());
        }
예제 #3
0
        public virtual async Task <int> Create(IObjectRequest entityRequest)
        {
            var entity = Mapper.Map <T>(entityRequest);

            if (entity == null)
            {
                throw new LegitProductException("Invalid object");
            }
            entities.Add(entity);

            return(await context.SaveChangesAsync());
        }
예제 #4
0
        public async Task <int> Create(ProductCreateRequest request)
        {
            var product = new Entites.Product()
            {
                Name        = request.Name,
                Price       = request.Price,
                Description = request.Description,
                AppUser     = request.User,
            };

            context.Add(product);
            return(await context.SaveChangesAsync());
        }