public async Task <IActionResult> Index() { // Execution service rest pour initailisé le drop down //HttpClient client = new HttpClient(); //var url = "https://" + HttpContext.Request.Host.ToString(); //client.BaseAddress = new Uri(url); //client.DefaultRequestHeaders.Accept.Clear(); //client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); //HttpResponseMessage response = client.GetAsync("/api/Machine").Result; // Une autre facon d'initailisation plus simple var vw = new MachineViewModel(); var listeTypeBoisson = await machineService.ListAllTypeBoisson(); var dernierChoix = new CustumMachine(); if (!String.IsNullOrEmpty(HttpContext.User.Identity.Name)) { dernierChoix = machineService.SectionDernierChoix(HttpContext.User.Identity.Name); } var selectTypeBoison = listeTypeBoisson.Select(a => new SelectListItem() { Value = a.Id.ToString(), Text = a.DescriptionType, Selected = (dernierChoix != null && a.Id == dernierChoix.IdType) ? true : false }).ToList(); ViewBag.ListeTypeBoisson = selectTypeBoison; return(View()); }
/// <summary> /// Recupere le dernier chois d'utilisateur /// </summary> /// <param name="login"></param> /// <returns></returns> public CustumMachine SectionDernierChoix(string login) { // Vérifier si l'utilisateur a déja passe une commande var listCommnadeLogin = efSpecRepository.GetCommandeByLogin(login); // Retourner la commande au cas échanace retourner null if (listCommnadeLogin.Count > 0) { var selectionCommande = new CustumMachine { Login = login, IdType = listCommnadeLogin[0].IdTypeBoisson }; return(selectionCommande); } return(null); }
public async Task <IActionResult> Create(string IdTypeBoisson, bool Mug, int Quantite) { var message = ""; var custumMachine = new CustumMachine { Quantite = Quantite, IdType = IdTypeBoisson, Mug = Mug, Login = HttpContext.User.Identity.Name }; var machine = await machineService.ConstructionCafe(custumMachine); if (machine != null) { message = machine.IdTypeBoissonNavigation.DescriptionType; } return(Json(message)); }
public async Task <IActionResult> Create(MachineViewModel machineViewModel) { try { var custumMachine = new CustumMachine { Quantite = machineViewModel.Quantite ?? 0, IdType = machineViewModel.IdTypeBoisson, Mug = machineViewModel.Mug, Login = HttpContext.User.Identity.Name }; await machineService.ConstructionCafe(custumMachine); return(RedirectToAction(nameof(Index))); } catch { return(View(machineViewModel)); } }
/// <summary> /// /// </summary> /// <param name="custumMachine"></param> /// <returns></returns> public async Task <Commande> ConstructionCafe(CustumMachine custumMachine) { // Vérifier la quantite du boisson choisi var boissonType = await asyncTypeRepository.GetByIdAsync(custumMachine.IdType); if (boissonType is null) { _logger.LogWarning("boisson n'esxiste pas"); throw new ArgumentNullException("Idtype", "Votre choix.... "); } else { if (boissonType.Quantite > 0) { // Reduire la quatite de la quantite consomme boissonType.Quantite--; await asyncTypeRepository.UpdateAsync(boissonType); // Construction commande var command = new Commande { Id = Guid.NewGuid().ToString(), DateComande = DateTime.Now, IdTypeBoisson = custumMachine.IdType, Login = custumMachine.Login, Mug = custumMachine.Mug }; // Sauvgarder la commande return(await asyncCommandeRepository.AddAsync(command)); } else { _logger.LogWarning("Boisson " + boissonType.DescriptionType + " terminé"); throw new Exception("Il n'a plus de" + boissonType.DescriptionType); } } }