Ejemplo n.º 1
0
        public async Task <bool> CreateStore(StoreViewModel storeView)
        {
            try
            {
                var store = new Store
                {
                    StoreName = storeView.StoreName,
                    Phone     = storeView.Phone,
                    Email     = storeView.Email,
                    Street    = storeView.Street,
                    City      = storeView.City,
                    State     = storeView.State,
                    ZipCode   = storeView.ZipCode
                };
                _context.Store.Add(store);
                await _context.SaveChangesAsync();

                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(false);
            }
        }
Ejemplo n.º 2
0
        public async Task <bool> CreateUser(AddUserViewModel userView)
        {
            try
            {
                var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/images", userView.Picture.FileName);
                using (var stream = new FileStream(path, FileMode.Create))
                {
                    await userView.Picture.CopyToAsync(stream);
                }
                var user = new User
                {
                    Email    = userView.Email,
                    PassWord = Infrastructure.SecurePasswordHasher.Hash(userView.PassWord),
                    FullName = userView.FullName,
                    Phone    = userView.Phone,
                    Picture  = userView.Picture.FileName,
                    Address  = userView.Address,
                    IsActive = userView.IsActive,
                    StoreId  = userView.StoreId
                };
                _context.User.Add(user);
                await _context.SaveChangesAsync();

                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(false);
            }
        }
Ejemplo n.º 3
0
        public async Task <bool> CreateStock(StockViewModel addStock)
        {
            try
            {
                var checkStock = await _context.Stock.FindAsync(addStock.ProductId, addStock.StoreId);

                if (checkStock != null)
                {
                    checkStock.Quantity += addStock.Quantity;
                    _context.Stock.Update(checkStock);
                    await _context.SaveChangesAsync();
                }
                else
                {
                    var stock = new Stock
                    {
                        ProductId = addStock.ProductId,
                        StoreId   = addStock.StoreId,
                        Quantity  = addStock.Quantity
                    };
                    _context.Stock.Add(stock);
                    await _context.SaveChangesAsync();
                }

                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(false);
            }
        }
Ejemplo n.º 4
0
        public async Task <bool> CreateProduct(ActionProductViewModel addProduct)
        {
            try
            {
                var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/images", addProduct.Picture.FileName);
                using (var stream = new FileStream(path, FileMode.Create))
                {
                    await addProduct.Picture.CopyToAsync(stream);
                }
                var product = new Product()
                {
                    ProductName = addProduct.ProductName,
                    BrandId     = addProduct.BrandId,
                    CategoryId  = addProduct.CategoryId,
                    ModelYear   = addProduct.ModelYear,
                    ListPrice   = addProduct.ListPrice,
                    Picture     = addProduct.Picture.FileName
                };
                _context.Product.Add(product);
                await _context.SaveChangesAsync();

                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(false);
            }
        }
Ejemplo n.º 5
0
        public async Task <bool> CreateCustomer(CustomerViewModel customers)
        {
            try
            {
                var customer = new Customer()
                {
                    FirstName = customers.FirstName,
                    LastName  = customers.LastName,
                    Phone     = customers.Phone,
                    Email     = customers.Email,
                    Street    = customers.Street,
                    City      = customers.City,
                    State     = customers.State,
                    ZipCode   = customers.ZipCode
                };
                _context.Customer.Add(customer);
                await _context.SaveChangesAsync();

                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(false);
            }
        }
Ejemplo n.º 6
0
        public async Task <bool> CreateBrand(BrandViewModel createBrand)
        {
            try
            {
                var brand = new Brand
                {
                    BrandName = createBrand.BrandName
                };
                _context.Brand.Add(brand);
                await _context.SaveChangesAsync();

                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(false);
            }
        }
Ejemplo n.º 7
0
        public async Task <bool> CreateCategory(CategoryViewModel addCategory)
        {
            try
            {
                var category = new Category()
                {
                    CategoryName = addCategory.CategoryName
                };
                _context.Category.Add(category);
                await _context.SaveChangesAsync();

                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(false);
            }
        }