Ejemplo n.º 1
0
        /// <inheritdoc />
        /// <summary>
        /// AddAsync
        /// </summary>
        /// <param name="userViewModel">IndexViewModel</param>
        /// <returns>Could Be Addted?</returns>
        public async Task <bool> AddAsync(UserViewModel userViewModel)
        {
            try
            {
                var users = new User
                {
                    Email    = userViewModel.Email,
                    Fullname = userViewModel.FullName,
                    Password = SecurePasswordHasher.Hash(userViewModel.Password),
                    Phone    = userViewModel.Phone,
                    IsActive = userViewModel.IsActive,
                    StoreId  = userViewModel.StoreId,
                    Role     = userViewModel.Role
                };
                _context.User.Add(users);
                await _context.SaveChangesAsync();

                return(true);
            }
            catch (Exception e)
            {
                Log.Error("Add User Async Error: {0}", e.Message);
                return(false);
            }
        }
Ejemplo n.º 2
0
        /// <inheritdoc />
        /// <summary>
        /// AddAsync
        /// </summary>
        /// <param name="product">ProductViewModel</param>
        /// <returns>Could Be Addted?</returns>
        public async Task <bool> AddAsync(ProductViewModel product)
        {
            try
            {
                var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/images", product.ImageFile.FileName);
                using (var stream = new FileStream(path, FileMode.Create))
                {
                    await product.ImageFile.CopyToAsync(stream);
                }
                var products = new Product
                {
                    ProductName = product.ProductName,
                    BrandId     = product.BrandId,
                    CategoryId  = product.CategoryId,
                    ModelYear   = product.ModelYear,
                    ListPrice   = product.ListPrice,
                    Image       = product.ImageFile.FileName
                };
                _context.Product.Add(products);
                await _context.SaveChangesAsync();

                return(true);
            }
            catch (Exception e)
            {
                Log.Error("Add Product Async Error:{0}", e.Message);
                return(false);
            }
        }
Ejemplo n.º 3
0
        /// <inheritdoc />
        /// <summary>
        /// AddAsync
        /// </summary>
        /// <param name="stockViewModel">StockViewModel</param>
        /// <returns>Could Be Addted?</returns>
        public async Task <bool> AddAsync(StockViewModel stockViewModel)
        {
            try
            {
                var st = await _context.Stock.FindAsync(stockViewModel.ProductId, stockViewModel.StoreId);

                if (st != null)
                {
                    st.Quantity += stockViewModel.Quantity;
                    _context.Stock.Update(st);
                    await _context.SaveChangesAsync();

                    return(true);
                }
                var stocks = new Stock
                {
                    StoreId   = stockViewModel.StoreId,
                    ProductId = stockViewModel.ProductId,
                    Quantity  = stockViewModel.Quantity
                };
                _context.Stock.Add(stocks);
                await _context.SaveChangesAsync();

                return(true);
            }
            catch (Exception e)
            {
                Log.Error("Add Stock Async Error: {0}", e.Message);
                return(false);
            }
        }
Ejemplo n.º 4
0
        /// <inheritdoc />
        /// <summary>
        /// AddAsync
        /// </summary>
        /// <param name="store">StoreViewModel</param>
        /// <returns>Could Be Addted?</returns>
        public async Task <bool> AddAsync(StoreViewModel store)
        {
            try
            {
                var stores = new Store
                {
                    StoreName = store.StoreName,
                    Phone     = store.Phone,
                    Email     = store.Email,
                    Street    = store.Street,
                    City      = store.City,
                    State     = store.State,
                    ZipCode   = store.ZipCode
                };
                _context.Store.Add(stores);
                await _context.SaveChangesAsync();

                return(true);
            }
            catch (Exception e)
            {
                Log.Error("Add Store Async Error: {0}", e.Message);
                return(false);
            }
        }
Ejemplo n.º 5
0
        /// <inheritdoc />
        /// <summary>
        /// AddAsync
        /// </summary>
        /// <param name="category">CategoryViewModel</param>
        /// <returns>Could Be Addted?</returns>
        public async Task <bool> AddAsync(CategoryViewModel category)
        {
            try
            {
                var categorys = new Category
                {
                    CategoryName = category.CategoryName
                };
                _context.Category.Add(categorys);
                await _context.SaveChangesAsync();

                return(true);
            }
            catch (Exception e)
            {
                Log.Error("Add Categoy Async Error: {0}", e.Message);
                return(false);
            }
        }
Ejemplo n.º 6
0
        /// <inheritdoc />
        /// <summary>
        /// AddAsync
        /// </summary>
        /// <param name="brand">BrandViewModel</param>
        /// <returns>Could be Addted?</returns>
        public async Task <bool> AddAsync(BrandViewModel brand)
        {
            try
            {
                var brands = new Brand
                {
                    BrandName = brand.BrandName
                };
                _context.Brand.Add(brands);
                await _context.SaveChangesAsync();

                return(true);
            }
            catch (Exception e)
            {
                Log.Error("Add Brand Async Error: {0}", e.Message);
                return(false);
            }
        }