public int AddCigarettes(Cigarettes cigarettes) { int insertSuccess = 0; _context.Cigarettes.Add(cigarettes); insertSuccess = _context.SaveChanges(); return(insertSuccess); }
public int UpdateCigarettes(int id, Cigarettes cigarettes) { int updateSuccess = 0; var target = _context.Cigarettes.SingleOrDefault(c => c.IdCigarettes == id); if (target != null) { _context.Entry(target).CurrentValues.SetValues(cigarettes); updateSuccess = _context.SaveChanges(); } return(updateSuccess); }
public IActionResult GetById(int id) { Cigarettes cigarettes = _repo.GetCigarettesById(id); if (cigarettes != null) { return(Ok(cigarettes)); } else { return(BadRequest("Oh tidak, data tidak ada")); } }
public IActionResult Post([FromForm] Cigarettes cigarettes) { if (!ModelState.IsValid) { return(BadRequest("Oops.. Ada yang error nih")); } int success = _repo.AddCigarettes(cigarettes); if (success == 1) { return(Created("api/cigarettes", cigarettes)); } return(BadRequest()); }
public IActionResult Put(int id, [FromForm] Cigarettes cigarettes) { if (!ModelState.IsValid) { return(BadRequest("Tidak ada data yang di edit")); } int success = _repo.UpdateCigarettes(id, cigarettes); if (success == 1) { return(Ok(cigarettes)); } return(BadRequest("Aduh... Editnya gagal")); }
/// <summary> /// Gets or sets house by a given cigarettes brand. /// </summary> /// <param name="cigarettes">A Cigarettes enumeration value.</param> /// <returns>The first found house or null if not found.</returns> public House this[Cigarettes cigarettes] { get { return(this.street.FirstOrDefault(h => h.Cigarettes == cigarettes)); } set { var house = this.street.FirstOrDefault(h => h.Cigarettes == cigarettes); if (house != null) { house.Cigarettes = cigarettes; } } }
static void Main(string[] args) { User user = new User( "Dan", "Йошкар-Ола, Сыктывкар", 10000, 0 ); Fruit apple = new Fruit( "Яблоко садовое, спелое, да короче", 12.90, "Сосед", "C, B", 1 ); Cigarettes bond = new Cigarettes( "Сигареты Бонд (с кнопкой)", 228.0, "Philip Morris International", "10 мг в пачке", 2 ); Drink pepsi = new Drink( "Pepsi кола", 45, "PepsiCo", "С говном", 3 ); Product[] products = new Product[] { apple, bond, pepsi }; Informator informer = new Informator(); while (true) { Console.WriteLine($"Здравствуйте, {user.Name}, ваш баланс - {user.Balance}, добро пожаловать в наш магазин \"Большой Эсс\"!"); Console.WriteLine($"\nНе забудьте сигареты!\n"); Console.WriteLine("Чтобы увидеть ассоритмент нажмите Enter"); Console.WriteLine("Чтобы выйти нажмите Esc"); ConsoleKeyInfo readedKeyInfo = Console.ReadKey(); ConsoleKey readedKey = readedKeyInfo.Key; if (readedKey == ConsoleKey.Escape) { break; } else if (readedKey == ConsoleKey.Enter) { Console.Clear(); Console.WriteLine($"Количество кэша: {user.Balance}, потрачено: {user.Spent}"); Console.WriteLine("Наш ассортимент:\n"); foreach (Product product in products) { product.ToConsole(); } Console.WriteLine("Введите номер товара и нажмите Enter: "); string readedProductIndex = Console.ReadLine(); int productIndex = Convert.ToInt32(readedProductIndex); informer.Buy(user, products[productIndex - 1]); } } }