public async Task <int> Add(AddProductViewModel addProductViewModel)
        {
            try
            {
                Product product = new Product()
                {
                    Name           = addProductViewModel.Name,
                    ImageUrl       = addProductViewModel.ImageUrl,
                    Description    = addProductViewModel.Description,
                    Price          = addProductViewModel.Price,
                    Quantity       = addProductViewModel.Quantity,
                    CategoryId     = addProductViewModel.CategoryId,
                    SupplierId     = addProductViewModel.SupplierId,
                    PromotionPrice = addProductViewModel.PromotionPrice,
                    Warranty       = addProductViewModel.Warranty,
                    Frame          = addProductViewModel.Frame,
                    Rims           = addProductViewModel.Rims,
                    Tires          = addProductViewModel.Tires,
                    Weight         = addProductViewModel.Weight,
                    WeightLimit    = addProductViewModel.WeightLimit,
                    Status         = addProductViewModel.Status,
                    ShowOnHome     = addProductViewModel.ShowOnHome
                };
                _daxoneDBContext.Products.Add(product);
                int res = await _daxoneDBContext.SaveChangesAsync();

                return(res);
            }
            catch (Exception)
            {
                return(-1);
            }
        }
        public async Task <IActionResult> PutAbout(long id, About about)
        {
            if (id != about.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Exemple #3
0
        public async Task <int> Add(AddOrderViewModel orderViewModel)
        {
            Order order = new Order()
            {
                OrderName     = orderViewModel.OrderName,
                OrderAddress  = orderViewModel.OrderAddress,
                OrderEmail    = orderViewModel.OrderEmail,
                OrderPhone    = orderViewModel.OrderPhone,
                OrderNote     = orderViewModel.OrderNote,
                TotalMoney    = orderViewModel.TotalMoney,
                PaymentStatus = 0
            };

            _daxoneDBContext.Orders.Add(order);
            var res = await _daxoneDBContext.SaveChangesAsync();

            var ods = JsonConvert.DeserializeObject <List <OrderDetailViewModel> >(orderViewModel.OrderDetails);

            foreach (var p in ods)
            {
                OrderDetail od = new OrderDetail()
                {
                    ProductId = p.Id,
                    OrderId   = order.Id,
                    Price     = p.Price,
                    Quantity  = p.Quantity
                };
                _daxoneDBContext.OrderDetails.Add(od);
                await _daxoneDBContext.SaveChangesAsync();
            }
            return(res);
        }
Exemple #4
0
        public async Task <int> Add(AddSupplierViewModel addSupplierViewModel)
        {
            try
            {
                Supplier supplier = new Supplier()
                {
                    Name    = addSupplierViewModel.Name,
                    Address = addSupplierViewModel.Address,
                    Email   = addSupplierViewModel.Email,
                    Phone   = addSupplierViewModel.Phone,
                    Status  = addSupplierViewModel.Status
                };
                _daxoneDBContext.Suppliers.Add(supplier);
                int res = await _daxoneDBContext.SaveChangesAsync();

                return(res);
            }
            catch (Exception)
            {
                return(-1);
            }
        }
Exemple #5
0
        public async Task <int> Register(UserRegisterViewModel userRegisterViewModel)
        {
            User user = new User()
            {
                Username = userRegisterViewModel.Username,
                Password = userRegisterViewModel.Password,
                Address  = userRegisterViewModel.Address,
                Email    = userRegisterViewModel.Email,
                Phone    = userRegisterViewModel.Phone
            };

            _daxoneDBContext.Users.Add(user);
            int res = await _daxoneDBContext.SaveChangesAsync();

            return(res);
        }