public IActionResult OnGet(long id) { userName = Request.Cookies["userName"]; Id = id; Dbo.ClientItems item = StockRepository.Get().Result.FirstOrDefault(it => it.Id == id); if (item == null) { return(RedirectToPage("/")); } Name = item.Name; Price = item.Price; Stock = item.Stock; PicName = item.PicName; Type = StockRepository.GetTypes().FirstOrDefault(t => t.Id == item.TypeId).Name; return(Page()); }
public async Task <IActionResult> OnPostAsync() { long id = long.Parse(Request.Form["Id"]); PicName = Request.Form["Image"]; if (PicName == "") // Quand l'user n'a pas fourni d'image, on reprend celle d'avant { PicName = _stockRepository.Get().Result.FirstOrDefault(it => it.Id == id).PicName; } long TypeId = 0; if (Type == null) // Pareil pour le type { TypeId = _stockRepository.Get().Result.FirstOrDefault(it => it.Id == id).TypeId; } else { TypeId = long.Parse(Type); } Dbo.ClientItems item = new Dbo.ClientItems { Id = id, Name = Name, PicName = PicName, Stock = Stock, Price = Price, TypeId = TypeId }; var result = _stockRepository.Update(item).Result; ClientLogs log = new ClientLogs { Id = 0, Date = DateTime.Now, Class = this.GetType().Name, Type = "Update", Logtype = LoggerType.INFO.GetFriendlyName(), Message = "Product: " + Name + " has been updated in the Stock base", }; await _logRepository.Insert(log); return(Redirect("/ProductDetail/" + id)); }
public IActionResult OnGet(long id) { userName = Tools.checkUser(Request.Cookies["user"], _employeeRepository, 1); if (userName == null) { return(RedirectToPage("/Login")); } resetTypeDropdownList(); this.Id = id; Dbo.ClientItems item = _stockRepository.Get().Result.FirstOrDefault(it => it.Id == id); if (item == null) { return(RedirectToPage("/")); } Name = item.Name; Price = item.Price; Stock = item.Stock; Type = _stockRepository.GetTypes().FirstOrDefault(t => t.Id == item.TypeId).Name; PicName = _stockRepository.Get().Result.FirstOrDefault(it => it.Id == id).PicName; return(Page()); }