public BillViewModel GetBill(int id) { Bill bill = db2.GetItem(id); return(new BillViewModel { Id = bill.Id, Name = bill.Name, Amount = bill.Amount, BookedAmount = bill.BookedAmount, FreeAmount = bill.FreeAmount, OrganisationId = bill.OrganisationId, OrganisationName = bill.Organisation.Name, OrganisationType = bill.Organisation.Type }); }
public async Task ExecuteAsync(Message message) { var cost = message.Text.Replace($"/{Name}", string.Empty).Trim(); if (double.TryParse(cost, out var costResult)) { var hardWare = _user.GetItem(z => z.TelegramUserId == message.Chat.Id); hardWare.Nvidia1070 = costResult; _user.Update(hardWare, z => z.TelegramUserId == message.Chat.Id); await _client.SendTextMessageAsync(message.Chat.Id, "Success"); } else { await _client.SendTextMessageAsync(message.Chat.Id, "Invalid cost"); } }
// // GET: /Product/Details/5 public ActionResult Details(int id) { var model = repository.GetItem(id); if (model == null) { RedirectToAction("Index"); } //if (model == null) //{ // Response.Write("Unable to locate Product"); // return null; //} return(View(model)); }
public Domain.DataTransfer.BoughtSong BuySong(int songId, int userId, decimal discountForBuyAllAlbum = 0) { if (songId <= 0 || userId <= 0) { throw new ArgumentException("userId is less then 1 or songId is less then 1 in musicStoreService in BuySong", "userId or songId"); } User user = _userRepository.GetItem(userId); if (user == null) { throw new Exception("User is null"); } Song song = _songRepository.GetItem(songId); if (song == null) { throw new Exception("Song is null"); } if (user.Money < song.Price) { throw new Exception($"User has not enough money for buy {song.Name} song"); } decimal songBoughtPrice = 0; songBoughtPrice = discountForBuyAllAlbum > 0 ? song.Price - (song.Price * (discountForBuyAllAlbum / 100)) : song.Price; BoughtSong boughtSong = new BoughtSong() { BoughtPrice = songBoughtPrice, IsVisible = true, BoughtDate = DateTime.Now, Song = song, User = user }; user.Money -= songBoughtPrice; _boughtSongRepository.Create(boughtSong); _userRepository.Update(user); var result = _mapBoughtSong.AutoMap(boughtSong); return(result); }
public int RenterMachine(int renterId, int machineId, DateTime starTime, DateTime endTime) { if (renterId <= 0 || machineId <= 0) { throw new ArgumentException("renterId is less then 1 or machineId is less then 1 in musicStoreService in BuySong", "renterId or machineId"); } Customer renter = _renterRepository.GetItem(renterId); if (renter == null) { throw new Exception("Renter is null"); } CloudResource machine = _machineRepository.GetItem(machineId); if (machine == null) { throw new Exception("Machine is null"); } if (machine.Lessor == null) { throw new Exception("Lessor of machine is null"); } Lessor lessor = machine.Lessor; if (renter.Money < machine.Price) { throw new Exception($"Renter has not enough money for rent {machine.Name} machine"); } string activationCode = "9873"; var renteredMachine = new RenteredResource(renter, machine, starTime, endTime, machine.Price, activationCode); var renteredMachineId = _renteredMachineRepository.Create(renteredMachine); renter.Money -= machine.Price; lessor.Money += machine.Price; _renterRepository.Update(renter); _lessorRepository.Update(lessor); return(renteredMachineId); }
public async Task ExecuteAsync(Message message) { var percentStr = message.Text.TrimEnd().Split(' '); if (percentStr.Length > 1) { if (double.TryParse(percentStr[1], out var percent)) { var user = _userRepository.GetItem(z => z.TelegramUserId == message.Chat.Id); user.PoloniexPercentChangeCost = percent; _userRepository.Update(user, z => z.TelegramUserId == message.Chat.Id); await _client.SendTextMessageAsync(message.Chat.Id, "Success"); return; } } await _client.SendTextMessageAsync(message.Chat.Id, "Not successful \nExample /poloniexCostChange 14,88"); }
public async Task ExecuteAsync(Message message) { var timeStr = message.Text.TrimEnd().Split(' '); if (timeStr.Length > 1) { if (double.TryParse(timeStr[1], out var time)) { var user = _userRepository.GetItem(z => z.TelegramUserId == message.Chat.Id); user.TimeToCheckBittrix = time; _userRepository.Update(user, z => z.TelegramUserId == message.Chat.Id); await _client.SendTextMessageAsync(message.Chat.Id, "Success"); return; } } await _client.SendTextMessageAsync(message.Chat.Id, "Not successful \nExample /bittrixTimeCompare 7"); }
public ActionResult Create(ShoppingCart cart, int shippingAddressId) { try { var customer = GetCustomerByLoginName(User.Identity.Name); var shippingAddress = addressRepo.GetItem(shippingAddressId); var order = Order.GetOrderFromCart(cart, customer, shippingAddress); orderRepo.AddItem(order); return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Details(int id) { var order = orderRepo.GetItem(id); if (order == null) { Response.Write("Invalid Order"); return(null); } order.Customer = customerRepo.GetItem(order.CustomerId); if (order.Customer.LoginName != User.Identity.Name) { return(RedirectToAction("Index")); } //throw new InvalidOperationException("Order customer does not match logged in user."); return(View(order)); }
private ScheduleModel GetScheduleModel(Schedule sched) { if (sched == null) { return(null); } var teacher = _userService.GetUser(sched.TeacherId); var classModel = _classService.GetClassModel(sched.ClassId); var subject = _repoSubject.GetItem(sched.SubjectId); var schedModel = Activator.CreateInstance <ScheduleModel>(); schedModel.Id = sched.Id; schedModel.Date = sched.Date; schedModel.Teacher = teacher; schedModel.Subject = subject.Name; schedModel.Class = classModel; return(schedModel); }
public IActionResult Display(int id) { List <SelectListItem> categorySelector = new List <SelectListItem>(); foreach (CategoryUI cat in repo.GetAllCategories().OrderBy(c => c.Name)) { categorySelector.Add(new SelectListItem() { Value = cat.Id.ToString(), Text = cat.Name }); } ItemUI item = repo.GetItem(id); CategoryUI category = repo.GetCategory(item.CategoryId); ItemVM vm = new ItemVM() { Item = item, Category = category, CategorySelector = categorySelector }; return(View(vm)); }
public IEnumerable <VaultUser> GetAllUsers(string id) { var vault = _userVaultRepository.GetItem(id); if (vault.AllowCreate != null) { if (vault.AllowRead == null) { return(vault.AllowCreate.ToList()); } else { return(vault.AllowRead?.Union(vault.AllowCreate).Distinct(new VaultUserEqualityComparer()).ToList()); } } else { return(vault.AllowRead?.ToList()); } }
public bool EditUserAccount(UserAccount userDomain) { if (userDomain == null) { throw new ArgumentNullException("userDomain", "Can not update user, because it is null"); } var userDataAccess = _userRepository.GetItem(userDomain.Id); var updatedUser = _mapUser.ReAutoMap(userDomain, userDataAccess); int result = _userRepository.Update(updatedUser); if (result > 0) { return(true); } return(false); }
public void SendByEmail(int orderId, string mailTo) { Order order = null; try { order = _orderRepository.GetItem(orderId); } catch (DomainModelsException e) { throw new ServiceException($"Ошибка в сервисе {nameof(OrderService)} в методе {nameof(SendByEmail)} при обращении к БД", e); } if (order == null) { return; } var message = new StringBuilder(); message.Append($"Дата списка: {order.OrderDate}\n"); message.Append($"Номер списка: {order.OrderID}\n"); message.Append("Список покупок:\n"); foreach (var orderDetail in order.OrderDetail) { message.Append($"Название: {orderDetail.Product.ProductName}, Цена: {orderDetail.ProductPrice?.ToString("c")}\n"); } message.Append("----------------------------------\n"); message.Append(""); message.Append($"Итого: {order.OrderDetail.Sum(x => x.ProductPrice)?.ToString("F")}"); try { _emailSender.Send(message.ToString(), mailTo); } catch (Exception ex) { throw new SendEmailException($"Возникла ошибка в сервисе {nameof(OrderService)} в методе {nameof(SendByEmail)} при отправке почты", ex); } }
public IActionResult Index() { if (ModelState.IsValid) { if (User.Identity.IsAuthenticated) { if (HttpContext.Session.GetString("panier") != null) { Commande panier_courant = JsonConvert.DeserializeObject <Commande>(HttpContext.Session.GetString("panier")); //associer table commande et produit en passant par detailProduit, pour afficher nom, poids foreach (DetailsCommande detail in panier_courant.DetailsCommande) { detail.IdproduitNavigation = repoProduit.GetItem(detail.Idproduit); } return(View(panier_courant.DetailsCommande)); } } } return(RedirectToAction("Index", "Home")); }
public IActionResult GetMachine(int id) { if (id < 1) { return(BadRequest("id is less then 1")); } try { var result = _machineService.GetItem(id); return(Ok(result)); } catch (ArgumentException) { return(BadRequest("id is less then 1")); } catch (Exception) { return(StatusCode(500)); } }
//TODO pour plusieurs images public IActionResult GetImage(int id) { Produit requestedProduit = repoProduit.GetItem(id); if (requestedProduit != null) { string webRootpath = _environment.WebRootPath; string folderPath = "\\images\\"; string im = requestedProduit.Image.OrderByDescending(i => i.CheminAcces).Select(i => i.CheminAcces).SingleOrDefault(); string fullPath = webRootpath + folderPath + im; if (System.IO.File.Exists(fullPath)) { FileStream fileOnDisk = new FileStream(fullPath, FileMode.Open); byte[] fileBytes; using (BinaryReader br = new BinaryReader(fileOnDisk)) { fileBytes = br.ReadBytes((int)fileOnDisk.Length); } //get content type var provider = new FileExtensionContentTypeProvider(); string contentType; if (!provider.TryGetContentType(fullPath, out contentType)) { contentType = "application/octet-stream"; } return(File(fileBytes, contentType)); } else { return(NotFound()); } } else { return(NotFound()); } }
public IList <Domain.DataTransfer.Song> GetSongsListFromAlbumAvailableForBuyByUser(int albumId, int userId) { if (albumId <= 0) { throw new ArgumentException($"{nameof(albumId)} is less then 1 in musicStoreDisplayService GetSongsListAvailableForBuyByUser", nameof(albumId)); } if (userId <= 0) { throw new ArgumentException($"{nameof(userId)} is less then 1 in musicStoreDisplayService GetSongsListAvailableForBuyByUser", nameof(userId)); } var user = _userRepository.GetItem(userId); if (user == null || user.BoughtSongs == null) { throw new Exception("user is null or user.BoughtSongs is null"); } var album = _albumRepository.GetItem(albumId); if (album == null || album.Songs == null) { throw new Exception("album is null or album.Songs is null"); } var domainSongsList = new List <Domain.DataTransfer.Song>(); foreach (var albumSong in album.Songs) { var coincidence = user.BoughtSongs.Any(x => x.Song.Id == albumSong.Id); if (!coincidence) { domainSongsList.Add(_mapSong.AutoMap(albumSong)); } } return(domainSongsList); }
public async Task Process(Message message) { var user = _userRepository .GetItem(x => x.TelegramUserId == message.Chat.Id); var command = _commands .SingleOrDefault(x => message.Text.Contains($"/{x.Name}")); if (command != null) { if (command.IsProtected && user == null) { await _client.SendTextMessageAsync(message.Chat.Id, "Sign in please"); return; } _logger.LogInformation("Process command", command.Name, message.Chat.Id); await command.ExecuteAsync(message); } else if (!message.Text.Contains("/")) { if (user == null) { await _client.SendTextMessageAsync(message.Chat.Id, "Sign in please"); return; } _logger.LogInformation("Process command", "information", message.Chat.Id); _commands.FirstOrDefault(z => z.Name == InformationCommand.NameCommand)?.ExecuteAsync(message); } else { _logger.LogInformation("Command not found", message.Chat.Id); await _client.SendTextMessageAsync(message.Chat.Id, "Command not found"); } }
public async Task ExecuteAsync(Message message) { var splitStr = message.Text.Split(' '); if (splitStr.Length != 2) { await _client.SendTextMessageAsync(message.Chat.Id, $"Not successful \nExample /{Name} BTC"); return; } var currency = splitStr[1].ToUpper(); var alert = _alertRepository.GetItem(z => z.UserId == message.Chat.Id && currency == z.NameCurrency); if (alert == null) { await _client.SendTextMessageAsync(message.Chat.Id, "Alert not found"); return; } _alertRepository.Delete(z => z.UserId == message.Chat.Id && currency == z.NameCurrency); await _client.SendTextMessageAsync(message.Chat.Id, "Success"); }
private async Task RefreshItemList() { Debug.WriteLine($"**** {this.GetType().Name}.{nameof(RefreshItemList)}"); if (FoodItem == null) { ShowIsBusySpinner = true; FoodItem = new ObservableCollection <OrderItem>(); ShowIsBusySpinner = false; } else { ShowIsBusySpinner = true; var itemsList = await _repo.GetItem(); if (itemsList != null) { FoodItem = new ObservableCollection <OrderItem>(itemsList); } ShowIsBusySpinner = false; } }
private async Task RefreshItemList() { Debug.WriteLine($"**** {this.GetType().Name}.{nameof(RefreshItemList)}"); if (Item == null) { ShowIsBusySpinner = true; Item = new ObservableCollection <IndividualItem>(); ShowIsBusySpinner = false; } else { ShowIsBusySpinner = true; var listOfItems = await _repository.GetItem(); if (listOfItems != null) { Item = new ObservableCollection <IndividualItem>(listOfItems); } ShowIsBusySpinner = false; } }
public List <PizzaDto> GetPizzaAtPriceOrderIds(int[] ids) { List <PizzaDto> pizzas = new List <PizzaDto>(); ids.ToList().ForEach(id => { OrderPrice orderPrice = _orderPriceRepository.GetItem(id); Price price = _priceRepository.GetItem(orderPrice.PriceId); Pizza pizza = _pizzaRepository.GetItem(price.PizzaId); PizzaDto foundPizza = pizzas.Find(value => value.Id == pizza.Id); if (foundPizza != null) { PriceDto priceDto = ConverPrice(price); priceDto.Count = orderPrice.Count; foundPizza.Prices.Add(priceDto); } else { PizzaDto pizzaDto = ConvertPizza(pizza); pizzaDto.Prices.First().Count = orderPrice.Count; pizzas.Add(pizzaDto); } }); return(pizzas); }
public Task <Item> GetItem(Guid playerId, Guid itemId) { return(_repository.GetItem(playerId, itemId)); }
public Category GetCategory(int id) { return(_repository.GetItem(id)); }
public async Task ExecuteAsync(Message message) { //испавить этот костыль //if (_hardwareRepository.GetItem(x => x.TelegramUserId == message.Chat.Id) == null) //{ // _hardwareRepository.Create(new Models.DataBase.HardwareCost() // { // TelegramUserId = message.Chat.Id // }); // return; //} var hardwareCost = _hardwareRepository.GetItem(x => x.TelegramUserId == message.Chat.Id); _profitMineService.SetCost(hardwareCost); List <ReportProfit> report = new List <ReportProfit>(); var s9 = await _profitMineService.GetProfit(ProfitMinerStore.minerS9); report.Add(new ReportProfit() { Name = "S9", Profit = s9 }); var l3 = await _profitMineService.GetProfit(ProfitMinerStore.minerL3); report.Add(new ReportProfit() { Name = "L3+", Profit = l3 }); var d3 = await _profitMineService.GetProfit(ProfitMinerStore.minerD3); report.Add(new ReportProfit() { Name = "D3", Profit = d3 }); var b8 = await _profitMineService.GetProfit(ProfitMinerStore.minerB8); report.Add(new ReportProfit() { Name = "B8", Profit = b8 }); var n70 = await _profitMineService.GetProfit(ProfitMinerStore.miner1070); report.Add(new ReportProfit() { Name = "1070", Profit = n70 }); var n80ti = await _profitMineService.GetProfit(ProfitMinerStore.miner1080ti); report.Add(new ReportProfit() { Name = "1080ti", Profit = n80ti }); await _client.SendTextMessageAsync(message.Chat.Id, '`' + string.Join(Environment.NewLine, report.Select(x => x.ToString())) + '`', ParseMode.Markdown); }
public async Task <Item> GetItem(Guid playerId, Guid itemId) { return(await _irep.GetItem(playerId, itemId));; }
// GET: ProduitController/Details/5 public ActionResult Details(int id) { return(View(repoProduit.GetItem(id))); }
/// <summary> /// Method updates product status for "saled", because the Deal is done /// </summary> /// <param name="product"></param> /// <param name="id"></param> public static void Deal(IRepository<Product> product, int id) { Console.WriteLine("Consratulations! You have bought the product {0} on address {1}", product.GetItem(id).name, product.GetItem(id).address); Product saledProduct = new Product(id, product.GetItem(id).name, product.GetItem(id).address, "saled"); product.Update(saledProduct); }
public Product Get(long id) { return(productRepository.GetItem(id.ToString())); }
public void Scan(string sku) { _scannedItems.Add(_repository.GetItem(sku)); }
/// <summary> /// Method choses manager for user (at random. All the managers want to earn more money) /// </summary> /// <param name="manager"></param> public static void ChooseManager(IRepository<Manager> manager) { Random rand = new Random(); Console.WriteLine("Your manager will be {0}", manager.GetItem(rand.Next(1, 10)).name); }