public IActionResult CloseDefferedSale(int id, decimal cashSum, decimal cashlessSum, int moneyWorkerId, int userId) { Sale sale = _saleService.All().First(b => b.Id == id); User user = _userService.All().FirstOrDefault(x => x.Id == userId); if (cashSum > 0) { _infoMoneyService.Create(new InfoMoney() { PaymentType = PaymentType.Cash, MoneyWorkerId = user.ShopId, MoneyOperationType = MoneyOperationType.Sale, Sum = cashSum, Sale = sale }); } if (cashlessSum > 0) { _infoMoneyService.Create(new InfoMoney() { PaymentType = PaymentType.Cashless, MoneyWorkerId = moneyWorkerId, MoneyOperationType = MoneyOperationType.Sale, Sum = cashlessSum, Sale = sale }); } return(RedirectToAction("CheckPrint", new { saleId = id, operationSum = cashSum + cashlessSum })); }
public IActionResult Expense() { var userName = HttpContext.User.Identity.Name; User user = _userService.All().First(u => u.Login == userName); ViewBag.ShopId = _shopService.All().FirstOrDefault(s => s.Id == user.ShopId); ViewBag.CategoryExpense = _expenseCategoryService.All(); ViewBag.Shops = _db.Shops.ToList(); return(View()); }
public bool DeleteUser(Domain.User user) { bool success = false; Data.Entities.User x = _db.User.Where(a => a.Username.Equals(user.username)).FirstOrDefault(); if (x != null) { _db.User.Remove(x); success = true; } return(success); }
public IActionResult Products() { var userName = HttpContext.User.Identity.Name; User user = _userService.All().First(u => u.Login == userName); Shop shop = _shopService.All().First(s => s.Id == user.ShopId); ViewBag.Categories = _categoryService.All(); ViewBag.Shops = _shopService.All(); ViewBag.UserId = user.Id; var result = ProductService.GetProductsInStock(_db, _postgresContext); return(View(result)); }
public bool AddUser(Domain.User user) { bool check = false; Data.Entities.User x = _db.User.Where(a => a.Username.Equals(user.username)).FirstOrDefault(); if (x != null) { check = false; } else { _db.User.Add(Mapper.Map(user)); check = true; } return(check); }
public IActionResult BookingList() { var userName = HttpContext.User.Identity.Name; User user = _userService.All().First(u => u.Login == userName); Shop shop = _shopService.All().First(s => s.Id == user.ShopId); return(View(_bookingService.All() .Where(x => x.ShopId == shop.Id) .OrderByDescending(x => x.Id) .Select(x => new BookingListVM() { Date = x.Date, Id = x.Id, Debt = x.Debt, Pay = x.Pay, Sum = x.Sum, Status = x.Status, ProductTitle = _bookingProductService.All() .Include(z => z.Product).FirstOrDefault(z => z.BookingId == x.Id).Product.Title ?? "" }))); }
public async Task <IActionResult> GetMoneyWorkersForSale(int value) { var userName = HttpContext.User.Identity.Name; User user = _userService.All().First(u => u.Login == userName); if (value == 1) //Получить держателей карт { var archiveCardKeepers = _postgresContext.ArchiveCardKeepers .Select(x => x.CardKeeperId).ToList(); //TODO: _db??? var cardKeepers = _db.CardKeepers .Where(x => !archiveCardKeepers.Contains(x.Id)) .ToList(); return(Ok(cardKeepers)); } if (value == 2) // получить рассчетные счета { var archiveCalculatedScores = _postgresContext.ArchiveCalculatedScores .Select(x => x.CalculatedScoreId).ToList(); //TODO: _db??? var scores = _db.CalculatedScores .Where(x => !archiveCalculatedScores.Contains(x.Id)) .ToList(); return(Ok(scores)); } if (value == 3) // получить кассу { //TODO: _db??? var shops = _db.Shops.Where(x => x.Id == user.ShopId).ToList(); return(Ok(shops)); } return(BadRequest()); }
public async Task <IActionResult> GetMoneyWorkers(int value) { var userName = HttpContext.User.Identity.Name; User user = _userService.All().First(u => u.Login == userName); if (value == 1) //Получить держателей карт { //TODO: _db??? var cardKeepers = await _db.CardKeepers.Where(ck => ck.ForManager).ToListAsync(); return(Ok(cardKeepers)); } if (value == 3) { //TODO: _db??? var shop = await _db.Shops.Where(s => s.Id == user.ShopId).ToArrayAsync(); return(Ok(shop)); } return(BadRequest()); }
public IActionResult BookingClose(int id, decimal cashSum, decimal cashlessSum, int moneyWorkerId, bool cashless) { var userName = HttpContext.User.Identity.Name; User user = _userService.All().First(u => u.Login == userName); if (user == null) { throw new Exception("Пользователь не найден"); } Booking booking = _bookingService.All().First(b => b.Id == id); booking.Debt -= (cashSum + cashlessSum); booking.Pay += (cashSum + cashlessSum); if (booking.Debt <= 0) { booking.Status = BookingStatus.Close; } _bookingService.Update(booking); if (cashSum > 0) { _infoMoneyService.Create(new InfoMoney() { PaymentType = PaymentType.Cash, MoneyWorkerId = user.ShopId, MoneyOperationType = MoneyOperationType.Booking, Sum = cashSum, BookingId = booking.Id }); } if (cashlessSum > 0) { _infoMoneyService.Create(new InfoMoney() { PaymentType = PaymentType.Cashless, MoneyWorkerId = moneyWorkerId, MoneyOperationType = MoneyOperationType.Booking, Sum = cashlessSum, BookingId = booking.Id }); } if (booking.Status != BookingStatus.Close) { return(RedirectToAction("CheckPrint", new { bookingId = booking.Id, operationSum = cashSum + cashlessSum })); } int createdSaleId = 0; if (booking.Status == BookingStatus.Close) { var b_products = _bookingProductService.All() .Where(bp => bp.BookingId == booking.Id) .ToList(); decimal primeCost = 0; var sale = new Sale() { Date = DateTime.Now.AddHours(3), ShopId = user.ShopId.Value, PartnerId = booking.PartnerId, Sum = booking.Sum, CashSum = _infoMoneyService.All() .Where(x => x.BookingId == booking.Id && x.PaymentType == PaymentType.Cash) .Sum(x => x.Sum), CashlessSum = _infoMoneyService.All() .Where(x => x.BookingId == booking.Id && x.PaymentType == PaymentType.Cashless) .Sum(x => x.Sum), Payment = true, SaleType = SaleType.Booking, Discount = booking.Discount, ForRussian = booking.forRussian }; var createdSale = _saleService.Create(sale); _infoMoneyService.All() .Where(x => x.BookingId == booking.Id) .ToList() .ForEach(x => { x.SaleId = sale.Id; _infoMoneyService.Update(x); }); _saleInformationService.Create(new SaleInformation { SaleId = createdSale.Id, SaleType = SaleType.Booking }); foreach (var p in b_products) { _saleProductService.Create(new SaleProduct() { Amount = p.Amount, ProductId = p.ProductId, SaleId = sale.Id, Additional = p.Additional, Cost = p.Cost }); primeCost += _productOperationService.RealizationProduct(_db, p.ProductId, p.Amount, createdSale.Id); } sale.PrimeCost = primeCost; sale.Margin = sale.Sum - sale.PrimeCost; createdSaleId = createdSale.Id; _saleService.Update(createdSale); } if (createdSaleId != 0) { var managerId = _postgresContext.BookingManagersOld .FirstOrDefault(x => x.BookingId == id).ManagerId; _postgresContext.SaleManagersOld.Add( new SaleManagerOld(managerId, createdSaleId, booking.Date)); _postgresContext.SaveChanges(); } return(RedirectToAction("CheckPrint", new { saleId = createdSaleId, operationSum = cashSum + cashlessSum })); }
public IActionResult Get(int id) { User user = _userService.All().FirstOrDefault(u => u.Id == id); var shopId = user.ShopId; var bookedProducts = _db.BookingProducts .Where(x => x.Booking.Status == BookingStatus.Open) .Select(x => new { ProductId = x.ProductId, Amount = x.Amount }) .ToList() .GroupBy(x => x.ProductId) .Select(x => new { ProductId = x.Key, Amount = x.Sum(z => z.Amount) }) .ToList(); var incompleteProducts = _postgresContext.IncompleteProducts .Select(x => new { ProductId = x.ProductId, Amount = x.Amount }).ToList() .GroupBy(x => x.ProductId) .Select(x => new { ProductId = x.Key, Amount = x.Sum(z => z.Amount) }) .ToList(); var productsInStock = _db.SupplyProducts .Where(x => x.Product.ShopId == shopId) .Where(x => x.StockAmount > 0) .Select(x => new { ProductId = x.ProductId, Title = x.Product.Title, Cost = x.Product.Cost, Shop = x.Product.Shop, Category = x.Product.Category, Code = x.Product.Code, StockAmount = x.StockAmount }) .ToList() .GroupBy(x => x.ProductId) .Select(x => new ProductVM { Id = x.Key, Amount = x.Sum(z => z.StockAmount) - (bookedProducts .FirstOrDefault(z => z.ProductId == x.Key)?.Amount ?? 0) - (incompleteProducts .FirstOrDefault(z => z.ProductId == x.Key)?.Amount ?? 0), Title = x.FirstOrDefault().Title, Cost = x.FirstOrDefault().Cost, Shop = x.FirstOrDefault().Shop, Category = x.FirstOrDefault().Category, Code = x.FirstOrDefault().Code, BookedCount = bookedProducts.FirstOrDefault(z => z.ProductId == x.Key)?.Amount ?? 0 }) .ToList(); return(Ok(productsInStock)); }
public void UpdateTeamTest() { Data.Entities.HLContext _db = new Data.Entities.HLContext(); Data.TeamRepository test = new Data.TeamRepository(_db); Data.UserRepository usertest = new Data.UserRepository(_db); //preliminary stuff to clean database in case this stuff is already in there //first see if the team used in this test is in the DB Data.Entities.Team isthisteamhere = _db.Team.Where(o => o.Teamname.Equals("testteamname")).FirstOrDefault(); if (isthisteamhere != null) { //obtain the primary key for this team int primarykey = isthisteamhere.Id; //remove the userteam(s) associated with this team IEnumerable <UserTeam> ww = _db.UserTeam.Where(mm => mm.Teamid == primarykey); foreach (var item in ww) { _db.UserTeam.Remove(item); } _db.SaveChanges(); //now we can remove the team _db.Team.Remove(isthisteamhere); _db.SaveChanges(); } //now we can remove our user1 and 2 if they exist Data.Entities.User isthisuserhere = _db.User.Where(p => p.Username.Equals("username1")).FirstOrDefault(); if (isthisuserhere != null) { _db.User.Remove(isthisuserhere); _db.SaveChanges(); } Data.Entities.User isthisuserhere2 = _db.User.Where(p => p.Username.Equals("username2")).FirstOrDefault(); if (isthisuserhere2 != null) { _db.User.Remove(isthisuserhere2); _db.SaveChanges(); } bool what; //random bool to hold data about success of methods. bool success; //initialize boolean for asserts //first case, we pass the method a faulty team check for null case and count case. Domain.Team team = new Domain.Team(); success = test.UpdateTeam(team); Assert.AreEqual(success, false); //second test case for we have an empty team in the database and it is updated to contain a team. team.teamname = "testteamname"; Domain.User user = new Domain.User("username1", "password1"); //need to add user to db and pull it to get a stupid id success = usertest.DeleteUser(user); usertest.Save(); //add user to the database; success = usertest.AddUser(user); usertest.Save(); if (!success) { Assert.Fail(); } _db.SaveChanges(); //obtain the user from the database so it has the userID var x = _db.User.Where(a => a.Username.Equals(user.username)).FirstOrDefault(); Domain.User user1withID = Mapper.Map(x); team.Roles.Add(true); team.Userlist.Add(user1withID); what = test.DeleteTeam(team); what = test.AddTeam(team); //now I will add another user to the team and see if it updates. Domain.User user2 = new Domain.User("username2", "password2"); usertest.AddUser(user2); usertest.Save(); var xx = _db.User.Where(a => a.Username.Equals(user2.username)).FirstOrDefault(); Domain.User user2withID = Mapper.Map(xx); team.AddMember(user2withID); success = test.UpdateTeam(team); Assert.AreEqual(success, true); //keep database clean and undo the things i put in it //first remove the userteams //preliminary stuff to clean database in case this stuff is already in there //first see if the team used in this test is in the DB Data.Entities.Team isthisteamhere3 = _db.Team.Where(o => o.Teamname.Equals("testteamname")).FirstOrDefault(); if (isthisteamhere3 != null) { //obtain the primary key for this team int primarykey = isthisteamhere3.Id; //remove the userteam(s) associated with this team IEnumerable <UserTeam> ww = _db.UserTeam.Where(mm => mm.Teamid == primarykey); foreach (var item in ww) { _db.UserTeam.Remove(item); } _db.SaveChanges(); //now we can remove the team _db.Team.Remove(isthisteamhere3); _db.SaveChanges(); } //now we can remove our user1 and 2 if they exist Data.Entities.User isthisuserhere3 = _db.User.Where(p => p.Username.Equals("username1")).FirstOrDefault(); if (isthisuserhere3 != null) { _db.User.Remove(isthisuserhere3); _db.SaveChanges(); } Data.Entities.User isthisuserhere4 = _db.User.Where(p => p.Username.Equals("username2")).FirstOrDefault(); if (isthisuserhere4 != null) { _db.User.Remove(isthisuserhere4); _db.SaveChanges(); } }