Beispiel #1
0
        public async Task <IActionResult> EditWorkStock(EditWorkStockView details)
        {
            AppUser user = await userManager.FindByNameAsync(User.Identity.Name);

            Company   companyUser = userCompanyRepository.CompanyToUser(user.Id);
            WorkStock workStock   = workStockRepository.DisplayWorkStock(companyUser).Where(p => p.Id == details.SelectedWorkStock).
                                    FirstOrDefault();
            Tabaco       tabaco       = tabacosRepository.Tabacos.Where(x => x.Id == details.TabacoId).FirstOrDefault();
            CompanyStock companyStock = companyStockRepository.DisplayCompanyStock(companyUser)
                                        .Where(p => string.Equals(p.TabacoName, workStock.NameTabaco) && p.TabacoBundleWeigh == workStock.BundleTabacoWeigh)
                                        .FirstOrDefault();
            CompanyStock newCompanyStock = companyStockRepository.DisplayCompanyStock(companyUser).Where(p =>
                                                                                                         string.Equals(p.TabacoName, tabaco.Name) && p.TabacoBundleWeigh == tabaco.NominalWeigth).FirstOrDefault();

            if (workStock != null && companyStock != null && newCompanyStock != null)
            {
                workStockRepository.DeleteWorkStock(workStock);
                workStockRepository.AddWorkStock(new WorkStock
                {
                    Company           = companyUser,
                    NameTabaco        = tabaco.Name,
                    BundleTabacoWeigh = tabaco.NominalWeigth,
                    CountTabacoPack   = details.CountTabacoPack,
                    TabacoWeigh       = details.TabacoWeigth,
                    Data         = DateTime.Now,
                    HookahMaster = User.Identity.Name
                });
                companyStock.TabacoCount = companyStock.TabacoCount + workStock.CountTabacoPack;
                companyStockRepository.EditCompanyStock(companyStock);
                newCompanyStock.TabacoCount -= details.CountTabacoPack;
                companyStockRepository.EditCompanyStock(newCompanyStock);
            }
            return(RedirectToAction("ShowWorkStock", "Display"));
        }
        public async Task <IActionResult> ShowStock()
        {
            AppUser user = await userManager.FindByNameAsync(User.Identity.Name);

            var result = companyStockRepository.DisplayCompanyStock(userCompanyRepository.CompanyToUser(user.Id));

            return(View(result));
        }
Beispiel #3
0
        public async Task <IActionResult> AddTabacoToStock(ViewAddTabacoToStockList details)
        {
            AppUser user = await userManager.FindByNameAsync(User.Identity.Name);

            Company             companyUser = userCompanyRepository.CompanyToUser(user.Id);
            List <CompanyStock> data        = new List <CompanyStock>();

            if (details != null)
            {
                foreach (ViewAddTabacoToStock det in details.tabacoToStocks)
                {
                    Tabaco       tabaco         = tabacosRepository.Tabacos.Where(p => p.Id == det.TabacoId).FirstOrDefault();
                    CompanyStock repitCompStock = companyStockRepository.DisplayCompanyStock(companyUser).Where(
                        p => String.Equals(p.TabacoName, tabaco.Name, StringComparison.OrdinalIgnoreCase) &&
                        p.TabacoBundleWeigh == tabaco.NominalWeigth).FirstOrDefault();
                    if (repitCompStock != null)
                    {
                        repitCompStock.TabacoCount += det.TabacoCount;
                        companyStockRepository.EditCompanyStock(repitCompStock);
                    }
                    else
                    {
                        if (tabaco.Name != null)
                        {
                            data.Add(new CompanyStock
                            {
                                TabacoName        = tabaco.Name,
                                TabacoBundleWeigh = tabaco.NominalWeigth,
                                TabacoCount       = det.TabacoCount,
                                Company           = companyUser,
                            });
                        }
                    }
                }
                companyStockRepository.AddCompStocks(data);
            }
            return(RedirectToAction("ShowStock", "Display"));
        }