Ejemplo n.º 1
0
        // GET: Admini
        public ActionResult Index()
        {
            InventoryDBContext context = new InventoryDBContext();

            //gather data for admin dashboard

            ViewBag.Employees = (from a in context.Employees
                                 join e in context.Employees on a.ReportsToID equals e.EmployeeID
                                 select new EmployeeListViewModel
            {
                FirstName = a.FirstName,
                LastName = a.LastName,
                Birthdate = (DateTime)a.Birthdate,
                City = a.City,
                ReportsToName = e.FirstName,
                EmployeesID = a.EmployeeID
            }).ToList();
            ViewBag.Products = context.Products.Take(4).ToList();
            ViewBag.Orders   = context.OrderDetails.ToList();

            //determine if any product is low
            var lowproduct = (from p in context.Products
                              where p.UnitsInStock < 10
                              select p).ToList();

            ViewBag.LowProducts = lowproduct;
            return(View());
        }
Ejemplo n.º 2
0
        private void tbxBarcode_TextChanged(object sender, TextChangedEventArgs e)
        {
            var textbox = sender as TextBox;

            string inputBarcode = textbox.Text;

            InventoryDBContext inventoryDBContext = new InventoryDBContext();

            ItemRepository itemRepository = new ItemRepository();

            var existingItemByBarcode = itemRepository.GetItemByBarcodeNumber(inventoryDBContext, inputBarcode);

            if (existingItemByBarcode != null)
            {
                tbxProductName.Text    = existingItemByBarcode.Name;
                tbxBrandName.Text      = existingItemByBarcode.BrandName;
                tbxUnit.Text           = existingItemByBarcode.Unit;
                tbxStock.Text          = existingItemByBarcode.Stock.ToString();
                tbxSellingPrice.Text   = existingItemByBarcode.SellingPrice.ToString();
                tbxWholeSalePrice.Text = existingItemByBarcode.WholeSalePrice.ToString();
                tbxDescription.Text    = existingItemByBarcode.Description;
            }
            else
            {
                generalService = new GeneralService();
                generalService.TraverseVisualTree(this);
            }
        }
        public ProductHttpController(IHostingEnvironment hostingEnvironment, InventoryDBContext context)
        {
            m_Handler = new ProductHandler(context, this);

            m_HostingEnvironment = hostingEnvironment;
            _context             = context;
        }
Ejemplo n.º 4
0
        public async Task <ResponseViewModel <ConnectionStringViewModel> > IsServerExists(ConnectionStringViewModel Conn)
        {
            ResponseViewModel <ConnectionStringViewModel> ResObj = new ResponseViewModel <ConnectionStringViewModel>();

            try
            {
                ResObj.IsSuccess = false;
                string ConnectionString = await GetConnectionString(Conn);

                InventoryDBContext dbContext = new InventoryDBContext(ConnectionString);
                if (dbContext.Database.GetService <IRelationalDatabaseCreator>().Exists())
                {
                    ResObj.IsSuccess = true;
                }
                else
                {
                    dbContext.Database.EnsureCreated();
                    ResObj.IsSuccess = true;
                }
            }
            catch (Exception ex) {
                ResObj.IsSuccess    = false;
                ResObj.ErrorDetails = ex.ToString();
                ResObj.ErrorCode    = 500;
            }
            return(await Task.Run(() =>
            {
                return ResObj;
            }));
        }
Ejemplo n.º 5
0
 private void btnSubmit_Click(object sender, RoutedEventArgs e)
 {
     if (gotPhoneNumber && gotFname && gotLname && gotUsername && gotPassword && gotConfirmPassword &&
         gotEmail && gotAddress && comboBoxRoles.SelectedItem != null)
     {
         InventoryDBContext inventoryDBContext = new InventoryDBContext();
         RoleRepository     roleRepository     = new RoleRepository();
         User user = new User()
         {
             Username    = tbxUsername.Text,
             Address     = tbxAddress.Text,
             Email       = tbxEmail.Text,
             IsDisabled  = false,
             Password    = tbxPassword.Password,
             PhoneNumber = long.Parse(tbxPhoneNumber.Text),
             RoleId      = roleRepository.GetRoleByName(comboBoxRoles.Text.ToString()).RoleId,
         };
         inventoryDBContext.Users.Add(user);
         inventoryDBContext.SaveChanges();
         MessageBox.Show("User created successfully!");
         this.Close();
     }
     else
     {
         MessageBox.Show("Please, Check all fields!");
     }
 }
Ejemplo n.º 6
0
 public AuthentificationWindow()
 {
     InitializeComponent();
     authBtn.Background = Brushes.LightGreen;
     UserType           = "";
     baseColorBrush     = authBtn.Background;
     InventoryDBContext = new InventoryDBContext();
 }
Ejemplo n.º 7
0
        public IQueryable <Role> GetAllActiveRoles()
        {
            InventoryDBContext context = new InventoryDBContext();

            var roles = context.Roles.ToList().Where(x => x.IsActive == true).AsQueryable();

            return(roles);
        }
Ejemplo n.º 8
0
        public StockOut(InventoryDBContext context, StockDTO stockDTO)
        {
            ID                = stockDTO.ID;
            ProductID         = stockDTO.ProductID;
            TotalQuantity     = stockDTO.TotalQuantity;
            AvailableQuantity = stockDTO.AvailableQuantity;

            ProductDTO dto = context.GetProduct(stockDTO.ProductID);

            Product = new ProductOut(context, dto);
        }
        /// <summary>
        /// Method used for create and update brand, Pass Brand_Id=0 for create and Brand_Id>0 for update
        /// </summary>
        /// <param name="BrandObj"></param>
        /// <returns>Response Object</returns>
        public async Task <ResponseViewModel <BrandViewModel> > CreateAndUpdate(BrandViewModel BrandObj)
        {
            ResponseViewModel <BrandViewModel> ResObj = new ResponseViewModel <BrandViewModel>();

            try
            {
                if (BrandObj != null)
                {
                    bool IsNew = false;
                    InventoryDBContext dbContext = new InventoryDBContext(await connMethod.GetConnectionString(BrandObj.ConnectionString));
                    /*Check if already exists*/
                    Brand BrandDBObj  = dbContext.Brand.Where(x => x.Brand_Id == BrandObj.Brand_Id).FirstOrDefault();
                    bool  IsDuplicate = dbContext.Brand.Where(x => x.Name == BrandObj.Name && x.Brand_Id != BrandObj.Brand_Id).FirstOrDefault() != null?true:false;
                    if (!IsDuplicate)
                    {
                        if (BrandDBObj == null)
                        {
                            BrandDBObj = new Brand();
                            IsNew      = true;
                        }
                        BrandDBObj.Name = BrandObj.Name;
                        if (IsNew)
                        {
                            await dbContext.Brand.AddAsync(BrandDBObj);
                        }
                        await dbContext.SaveChangesAsync();

                        BrandObj.Brand_Id = BrandDBObj.Brand_Id;
                        ResObj.IsSuccess  = true;
                        List <BrandViewModel> BrandList = new List <BrandViewModel>();
                        BrandList.Add(BrandObj);
                        ResObj.Data = BrandList;
                    }
                    else
                    {
                        ResObj.IsSuccess    = false;
                        ResObj.ErrorCode    = 500;
                        ResObj.ErrorDetails = "Duplicate brand name.";
                    }
                }
                else
                {
                    ResObj.IsSuccess    = false;
                    ResObj.ErrorCode    = 400;
                    ResObj.ErrorDetails = "Parameter not provided.";
                }
            }
            catch (Exception ex) {
                ResObj.IsSuccess    = false;
                ResObj.ErrorCode    = 500;
                ResObj.ErrorDetails = ex.ToString();
            }
            return(ResObj);
        }
Ejemplo n.º 10
0
        public bool IsUsernameAvailable(string username)
        {
            if (string.IsNullOrEmpty(username))
            {
                return(false);
            }

            InventoryDBContext inventoryDBContext = new InventoryDBContext();
            var user = inventoryDBContext.Users.ToList().Select(x => x.Username.ToLower() == username.ToLower()).FirstOrDefault();

            return(!user);//if user is exist, return false otherwise true
        }
Ejemplo n.º 11
0
        public bool UsernamePasswordValidation(string userName, string password)
        {
            InventoryDBContext inventoryDBContext = new InventoryDBContext();

            if (string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(password))
            {
                throw new Exception("Invalid username or password!");
            }

            var user = inventoryDBContext.Users.ToList().Where(x => x.Username.ToLower() == userName.ToLower()).FirstOrDefault();

            return((user.Username.ToLower() == userName.ToLower() && user.Password == password) ? true : false);
        }
Ejemplo n.º 12
0
        public async Task <ResponseViewModel <QuantityViewModel> > CreateAndUpdate(QuantityViewModel QauntityObj)
        {
            ResponseViewModel <QuantityViewModel> ResObj = new ResponseViewModel <QuantityViewModel>();

            try
            {
                if (QauntityObj != null)
                {
                    bool IsNew = false;
                    InventoryDBContext dbContext = new InventoryDBContext(await connMethod.GetConnectionString(QauntityObj.ConnectionString));
                    /*Check if already exists*/
                    Brand_Quantity_Time_Received QuantityDBObj = dbContext.Brand_Quantity_Time_Received.Where(x => x.Inventory_Id == QauntityObj.Brand_Id).FirstOrDefault();
                    if (QuantityDBObj == null)
                    {
                        QuantityDBObj = new Brand_Quantity_Time_Received();
                        IsNew         = true;
                    }
                    QuantityDBObj.Brand_Id      = QauntityObj.Brand_Id;
                    QuantityDBObj.Quantity      = QauntityObj.Quantity;
                    QuantityDBObj.Time_Received = QauntityObj.Time_Received;
                    if (IsNew)
                    {
                        await dbContext.Brand_Quantity_Time_Received.AddAsync(QuantityDBObj);
                    }
                    await dbContext.SaveChangesAsync();

                    QauntityObj.Inventory_Id = QuantityDBObj.Inventory_Id;
                    ResObj.IsSuccess         = true;
                    List <QuantityViewModel> QuantityList = new List <QuantityViewModel>();
                    QuantityList.Add(QauntityObj);
                    ResObj.Data = QuantityList;
                }
                else
                {
                    ResObj.IsSuccess    = false;
                    ResObj.ErrorCode    = 400;
                    ResObj.ErrorDetails = "Parameter not provided.";
                }
            }
            catch (Exception ex)
            {
                ResObj.IsSuccess    = false;
                ResObj.ErrorCode    = 500;
                ResObj.ErrorDetails = ex.ToString();
            }
            return(ResObj);
        }
Ejemplo n.º 13
0
        public async Task <ResponseViewModel <QuantityViewModel> > Get(QuantityViewModel QauntityObj)
        {
            ResponseViewModel <QuantityViewModel> ResObj = new ResponseViewModel <QuantityViewModel>();

            try
            {
                if (QauntityObj != null)
                {
                    InventoryDBContext dbContext = new InventoryDBContext(await connMethod.GetConnectionString(QauntityObj.ConnectionString));
                    var Qauntity = (from Quantity in dbContext.Brand_Quantity_Time_Received.Where(x => x.Inventory_Id == QauntityObj.Inventory_Id || QauntityObj.Inventory_Id == 0)
                                    join brand in dbContext.Brand on Quantity.Brand_Id equals brand.Brand_Id
                                    select new QuantityViewModel {
                        Inventory_Id = Quantity.Inventory_Id,
                        Brand_Id = Quantity.Brand_Id,
                        Name = brand.Name,
                        Time_Received = Quantity.Time_Received,
                        Quantity = Quantity.Quantity
                    }
                                    ).ToList();
                    if (Qauntity.Count() > 0)
                    {
                        Qauntity[0].TotalQuantity = Qauntity.Sum(x => x.Quantity);
                        ResObj.Data      = JsonConvert.DeserializeObject <List <QuantityViewModel> >(JsonConvert.SerializeObject(Qauntity.ToList()));
                        ResObj.IsSuccess = true;
                    }
                    else
                    {
                        ResObj.IsSuccess    = false;
                        ResObj.ErrorCode    = 404;
                        ResObj.ErrorDetails = "No record found.";
                    }
                }
                else
                {
                    ResObj.IsSuccess    = false;
                    ResObj.ErrorCode    = 400;
                    ResObj.ErrorDetails = "Parameter not provided.";
                }
            }
            catch (Exception ex)
            {
                ResObj.IsSuccess    = false;
                ResObj.ErrorCode    = 500;
                ResObj.ErrorDetails = ex.ToString();
            }
            return(await Task.Run(() => { return ResObj; }));
        }
Ejemplo n.º 14
0
        private void createRolesAndUsers()
        {
            ApplicationDbContext context  = new ApplicationDbContext();
            InventoryDBContext   icontext = new InventoryDBContext();

            var roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(context));
            var userManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context));

            //Create Admin role if already not exists
            if (!roleManager.RoleExists("Admin"))
            {
                var role = new IdentityRole()
                {
                    Name = "Admin"
                };

                roleManager.Create(role);
            }
            //create jameel user if not already exists
            if (userManager.FindByName("Jameelbaig") == null)
            {
                var user = new ApplicationUser();
                user.UserName = "******";
                user.Email    = "*****@*****.**";
                string userpwd = "abcd123";

                var chkUser = userManager.Create(user, userpwd);

                //Add this user to Admin role
                if (chkUser.Succeeded)
                {
                    var result1 = userManager.AddToRole(user.Id, "Admin");
                }
            }

            //Add Employee Role
            if (!roleManager.RoleExists("Employee"))
            {
                var role = new IdentityRole()
                {
                    Name = "Employee"
                };
                roleManager.Create(role);
            }
        }
        public TransactionOut(InventoryDBContext context, TransactionDTO dto) : base(dto)
        {
            ProductDetails = new List <ProductOut>();

            // fill ProductDetails
            string[] IDs = dto.ProductIDs.Split(',');
            foreach (string sID in IDs)
            {
                if (!string.IsNullOrEmpty(sID))
                {
                    int ID = int.Parse(sID);
                    ProductDetails.Add(new ProductOut(context, context.GetProduct(ID)));
                }
            }
            if (dto.CustomerID != 0)
            {
                Customer = new CustomerOut(context, context.GetCustomer(dto.CustomerID));
            }
        }
Ejemplo n.º 16
0
        private void StartWebApp(string[] args)
        {
            var host = CreateWebHostBuilder(args).Build();

            using (host)
            {
                Logger = host.Services.GetRequiredService <ILogger <Program> >();
                try
                {
                    m_Context = new InventoryDBContext();
                    m_Context.Database.EnsureCreated();
                }
                catch (Exception ex)
                {
                    Logger.LogError(ex, "An error occurred creating the DB.");
                }

                host.Run();
            }
        }
Ejemplo n.º 17
0
        public PurchaseOut(InventoryDBContext context, PurchaseDTO dto)
            : base(dto)
        {
            this.ProductDetails = new List <ProductPurchaseDetails>();

            // products
            string[] productIDs          = dto.ProductIDs.Split(',');
            string[] productQuantities   = dto.ProductQuantities.Split(',');
            string[] productBuyingPrices = dto.ProductBuyingPrices.Split(',');
            int      numProducts         = productIDs.Length;

            for (int i = 0; i < numProducts; ++i)
            {
                int        id          = int.Parse(productIDs[i]);
                ProductOut productOut  = new ProductOut(context, context.GetProduct(id));
                int        Quantity    = int.Parse(productQuantities[i]);
                double     BuyingPrice = double.Parse(productBuyingPrices[i]);

                this.ProductDetails.Add(new ProductPurchaseDetails(productOut, Quantity, BuyingPrice));
            }
        }
Ejemplo n.º 18
0
        public async Task <ResponseViewModel <QuantityViewModel> > Delete(QuantityViewModel QuantityObj)
        {
            ResponseViewModel <QuantityViewModel> ResObj = new ResponseViewModel <QuantityViewModel>();

            try
            {
                if (QuantityObj != null)
                {
                    InventoryDBContext dbContext = new InventoryDBContext(await connMethod.GetConnectionString(QuantityObj.ConnectionString));
                    /*Check if already exists*/
                    Brand_Quantity_Time_Received QuantityDBObj = dbContext.Brand_Quantity_Time_Received.Where(x => x.Inventory_Id == QuantityObj.Inventory_Id).FirstOrDefault();
                    if (QuantityDBObj != null)
                    {
                        dbContext.Brand_Quantity_Time_Received.Remove(QuantityDBObj);
                        await dbContext.SaveChangesAsync();

                        ResObj.IsSuccess = true;
                    }
                    else
                    {
                        ResObj.IsSuccess    = false;
                        ResObj.ErrorCode    = 404;
                        ResObj.ErrorDetails = "Record not found.";
                    }
                }
                else
                {
                    ResObj.IsSuccess    = false;
                    ResObj.ErrorCode    = 400;
                    ResObj.ErrorDetails = "Parameter not provided.";
                }
            }
            catch (Exception ex)
            {
                ResObj.IsSuccess    = false;
                ResObj.ErrorCode    = 500;
                ResObj.ErrorDetails = ex.ToString();
            }
            return(ResObj);
        }
Ejemplo n.º 19
0
        public dynamic Upload(IFormCollection form)
        {
            var context = new InventoryDBContext();

            //var products = context.Items.FromSql(" INSERT INTO \"Items\" (\"Name\", \"Location\", \"Date_Purchased\", \"Quantity\", \"Type\", \"Photo\", \"Color\", \"Company\", \"Serial\") VALUES ("+ Request.Form["itemName"] + "," +  Request.Form["location"] + "," + Request.Form["dateBought"] + "," + Request.Form["numItems"] + "," +  Request.Form["type"] + "," +  Request.Form["color"] + "," + Request.Form["company"] + "," +  Request.Form["serial"] + "," + Request.Form["selectedFile"] +";");

            try
            {
                Items  newItem = CreateNewItem(form);
                Byte[] picture = null;
                foreach (var file in form.Files)
                {
                    picture = UploadFile(file);
                }
                newItem.Photo = picture;
                var items = context.Items.Add(newItem);
                context.SaveChanges();
                return(new { Success = true, newItem.Name });
            }
            catch (Exception ex)
            {
                return(new { Success = false, ex.Message });
            }
        }
Ejemplo n.º 20
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, InventoryDBContext inventoryDBContext)
        {
            //start
            app.UseAuthentication();
            //end

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseHttpsRedirection();

            app.UseSwagger();

            // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.),
            // specifying the Swagger JSON endpoint.
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
            });
            //Logger
            LogManager.LoadConfiguration(String.Concat(Directory.GetCurrentDirectory(), "/nlog.config"));
            app.UseRouting();

            app.UseAuthorization();

            inventoryDBContext.Database.Migrate();

            //inventoryDBContext.Database.EnsureCreated();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
Ejemplo n.º 21
0
        public IEnumerable <ResultItem> ReturnProducts()
        {
            var context  = new InventoryDBContext();
            var products = context.Items.FromSql("select * from \"Items\";").ToList();

            var allVal = from itm in products
                         select new { ID = itm.Id, Name = itm.Name, Company = itm.Company, Location = itm.Location, DatePurchased = itm.DatePurchased, Quantity = itm.Quantity, Color = itm.Color, Type = itm.Type, itm.Serial, itm.Photo };

            List <ResultItem> result = new List <ResultItem>();

            foreach (var item in allVal)
            {
                DateTime date          = (DateTime)item.DatePurchased;
                string   formattedDate = date.Date.ToString("MM-dd-yyyy");
                result.Add(new ResultItem {
                    Id = item.ID, Name = item.Name, Company = item.Company, Location = item.Location, DatePurchased = formattedDate, Quantity = item.Quantity, Color = item.Color, Type = item.Type, Serial = item.Serial, Photo = item.Photo
                });
            }


            IEnumerable <ResultItem> returnedResult = result;

            return(returnedResult);
        }
        /// <summary>
        /// Get the list of brand by passing brand_id=0 and a single brand by passing brand_id
        /// </summary>
        /// <param name="BrandObj"></param>
        /// <returns>response object</returns>
        public async Task <ResponseViewModel <BrandViewModel> > Get(BrandViewModel BrandObj)
        {
            ResponseViewModel <BrandViewModel> ResObj = new ResponseViewModel <BrandViewModel>();

            try
            {
                if (BrandObj != null)
                {
                    InventoryDBContext dbContext = new InventoryDBContext(await connMethod.GetConnectionString(BrandObj.ConnectionString));
                    var brand = dbContext.Brand.Where(x => x.Brand_Id == BrandObj.Brand_Id || BrandObj.Brand_Id == 0).ToList();
                    if (brand.Count() > 0)
                    {
                        ResObj.Data      = JsonConvert.DeserializeObject <List <BrandViewModel> >(JsonConvert.SerializeObject(brand.ToList()));
                        ResObj.IsSuccess = true;
                    }
                    else
                    {
                        ResObj.IsSuccess    = false;
                        ResObj.ErrorCode    = 404;
                        ResObj.ErrorDetails = "No record found.";
                    }
                }
                else
                {
                    ResObj.IsSuccess    = false;
                    ResObj.ErrorCode    = 400;
                    ResObj.ErrorDetails = "Parameter not provided.";
                }
            }
            catch (Exception ex) {
                ResObj.IsSuccess    = false;
                ResObj.ErrorCode    = 500;
                ResObj.ErrorDetails = ex.ToString();
            }
            return(await Task.Run(() => { return ResObj; }));
        }
Ejemplo n.º 23
0
        private void btnSubmit_Click(object sender, RoutedEventArgs e)
        {
            Item item = new Item()
            {
                Barcode        = tbxBarcode.Text,
                BrandName      = tbxBrandName.Text,
                Name           = tbxProductName.Text,
                Description    = tbxDescription.Text,
                SellingPrice   = float.Parse(tbxSellingPrice.Text),
                Stock          = int.Parse(tbxStock.Text),
                Unit           = tbxUnit.Text + " " + comboBoxUnit.Text,
                WholeSalePrice = float.Parse(tbxWholeSalePrice.Text),
            };
            InventoryDBContext inventoryDBContext = new InventoryDBContext();

            inventoryDBContext.Items.Add(item);
            inventoryDBContext.SaveChanges();

            //clear all fields
            generalService = new GeneralService();
            generalService.TraverseVisualTree(this);

            MessageBox.Show("Product added successfully!");
        }
 public CustomerOut(InventoryDBContext context, CustomerDTO customerDTO)
     : base(customerDTO)
 {
 }
Ejemplo n.º 25
0
 public ProductDAL(InventoryDBContext inventoryDBContext)
 {
     _inventoryDBContext = inventoryDBContext;
 }
 public VendorHandler(InventoryDBContext Context, VendorHttpController HttpController) : base(Context, HttpController)
 {
 }
Ejemplo n.º 27
0
 public UnitOfWork(InventoryDBContext context)
 {
     _context = context;
 }
Ejemplo n.º 28
0
        public Role GetRoleByName(string name)
        {
            InventoryDBContext context = new InventoryDBContext();

            return(context.Roles.FirstOrDefault(x => x.Name == name));
        }
Ejemplo n.º 29
0
 public StockDAL(InventoryDBContext inventoryDBContext)
 {
     _inventoryDBContext = inventoryDBContext;
 }
Ejemplo n.º 30
0
 public StockHandler(InventoryDBContext Context, StockHttpController HttpController)
     : base(Context, HttpController)
 {
 }