public async Task <IActionResult> Save(TRequest <RoomTypeRequest> request) { if (request == null) { return(NotFound()); } var response = new Response <int>(); try { if (request.value.Id == 0) { response.Data = await _roomTypeService.Add(request.value); response.Message = "Thêm thành công"; response.Success = true; } else { response.Data = await _roomTypeService.Update(request.value); response.Message = "Sửa thành công"; response.Success = true; } } catch (Exception ex) { response.Success = false; response.Message = ex.Message + "," + ex.InnerException; } return(Ok(response)); }
public ActionResult PostRoomType(RoomTypeDTO roomType) { string value = roomType.NameRoomType; string valuePrice = roomType.PriceRoom.ToString(); var list = _roomTypeService.GetAll(); // //Check Validate // if (value == "") // return NotFound (new { success = false, message = "Vui lòng nhập tên loại phòng" }); // if (valuePrice == "") // return NotFound (new { success = false, message = "Vui lòng nhập giá tiền" }); // else if (!int.TryParse(valuePrice, out int n)) // return NotFound (new { success = false, message = "Giá tiền không được chứa chữ" }); foreach (var rt in list) { string temp = rt.NameRoomType; if (temp.Equals(value, StringComparison.InvariantCultureIgnoreCase)) { return(NotFound(new { success = false, message = "Tên loại phòng đã tồn tại" })); } } _roomTypeService.Add(roomType); return(Ok(new { success = true, message = "Thêm thành công" })); }
public ActionResult Add(RoomTypeDto roomTypeDto) { _roomTypeService.Add(roomTypeDto); return(RedirectToAction("getAll", "RoomType")); }