public async Task <ProductResponse> AddProduct(ProductModel model)
        {
            var addProduct = new Product()
            {
                UserId                  = model.UserId,
                Title                   = model.Title,
                ShortDescription        = model.ShortDescription,
                FullDescription         = model.FullDescription,
                Price                   = model.Price,
                PriceCurrency           = model.PriceCurrency,
                PriceDiscountValue      = model.PriceDiscountValue,
                PriceDiscountPercentage = model.PriceDiscountPercentage,
                Unit                = model.Unit,
                Category            = model.Category,
                Size                = model.Size,
                Weight              = model.Weight,
                WeightUnit          = model.WeightUnit,
                InventoryAmount     = model.InventoryAmount,
                InventoryAdjustment = model.InventoryAdjustment,
                Status              = model.Status
            };

            await _dbContext.Products.AddAsync(addProduct);

            await _dbContext.SaveChangesAsync();

            return(new ProductResponse {
                Status = "200", Message = "Add Success"
            });
        }
Exemple #2
0
        public async Task <RegisterResponse> Register(CreateUserModel model)
        {
            var checkEmail = _dbContext.User.FirstOrDefault(customer => (customer.Email == model.Email));

            if (checkEmail != null)
            {
                return(new RegisterResponse {
                    Status = "999", Message = "Email exists"
                });
            }

            var checkPhone = _dbContext.User.FirstOrDefault(customer => (customer.Phone == model.Phone));

            if (checkPhone != null)
            {
                return(new RegisterResponse {
                    Status = "998", Message = "Phone exists"
                });
            }

            // TODO: add config mapper
            //var user = _mapper.Map<User>(registerRequest);

            var user = new User()
            {
                Email      = model.Email,
                Phone      = model.Phone,
                Password   = model.Password,
                Address    = model.Address,
                Fullname   = model.Fullname,
                Gender     = true,
                BusinessId = model.BusinessId
            };

            await _dbContext.User.AddAsync(user);

            await _dbContext.SaveChangesAsync();

            return(new RegisterResponse {
                Fullname = user.Fullname, Status = "200", Message = "Success"
            });
        }