public async Task <IActionResult> Create(CreateFuelViewModel model) { string message = String.Empty; if (ModelState.IsValid) { if (await _fuelServices.Create(model)) { message = "Nhiên liệu mới đã được tạo"; TempData["UserMessage"] = SystemUtilites.SendSystemNotification(NotificationType.Success, message); return(RedirectToAction(actionName: "Index")); } } message = "Lỗi không xác định, xin mời thao tác lại"; TempData["UserMessage"] = SystemUtilites.SendSystemNotification(NotificationType.Error, message); return(RedirectToAction(actionName: "Index")); }
public async Task <bool> Create(CreateFuelViewModel fuel) { try { Fuel newFuel = new Fuel() { FuelName = fuel.FuelName, FuelPrice = fuel.FuelPrice }; _context.Add(newFuel); var result = await _context.SaveChangesAsync(); return(result > 0); } catch (Exception) { return(false); } }